Skip to content

Commit 9df0158

Browse files
committed
Update and add new tests for the new features
1 parent 71cf683 commit 9df0158

6 files changed

Lines changed: 136 additions & 8 deletions

File tree

test/HelperContract.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {RuleAddressSetInvariantStorage} from
2525

2626
import {RuleSanctionsListInvariantStorage} from "src/rules/validation/abstract/RuleSanctionsListInvariantStorage.sol";
2727
// Rule interface
28+
import {IAddressList} from "src/rules/interfaces/IAddressList.sol";
2829

2930
// utils
3031
import "RuleEngine/../test/utils/CMTATDeployment.sol";

test/RuleBlacklist/RuleBlacklist.t.sol

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,78 @@ contract RuleBlacklistTest is Test, HelperContract {
2222
// Assert
2323
assertEq(message1, TEXT_CODE_NOT_FOUND);
2424
}
25+
26+
function testDetectTransferRestrictionOk() public {
27+
// Act
28+
resUint8 = ruleBlacklist.detectTransferRestriction(ADDRESS1, ADDRESS2, 20);
29+
// Assert
30+
assertEq(resUint8, NO_ERROR);
31+
32+
// With tokenId
33+
resUint8 = ruleBlacklist.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
34+
// Assert
35+
assertEq(resUint8, NO_ERROR);
36+
37+
// With tokenId
38+
resUint8 = ruleBlacklist.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
39+
// Assert
40+
assertEq(resUint8, NO_ERROR);
41+
42+
// Act
43+
resBool = ruleBlacklist.canTransfer(ADDRESS1, ADDRESS2, 20);
44+
// Assert
45+
assertEq(resBool, true);
46+
// Act
47+
resBool = ruleBlacklist.canTransfer(ADDRESS1, ADDRESS2, 0, 20);
48+
// Assert
49+
assertEq(resBool, true);
50+
}
51+
52+
function testDetectTransferRestrictionFRom() public {
53+
// Arrange
54+
vm.prank(DEFAULT_ADMIN_ADDRESS);
55+
ruleBlacklist.addAddress(ADDRESS1);
56+
// Act
57+
resUint8 = ruleBlacklist.detectTransferRestriction(ADDRESS1, ADDRESS2, 20);
58+
// Assert
59+
assertEq(resUint8, CODE_ADDRESS_FROM_IS_BLACKLISTED);
60+
61+
// With tokenId
62+
resUint8 = ruleBlacklist.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
63+
// Assert
64+
assertEq(resUint8, CODE_ADDRESS_FROM_IS_BLACKLISTED);
65+
66+
// Act
67+
resBool = ruleBlacklist.canTransfer(ADDRESS1, ADDRESS2, 20);
68+
// Assert
69+
assertFalse(resBool);
70+
71+
// Act
72+
resBool = ruleBlacklist.canTransfer(ADDRESS1, ADDRESS2, 0, 20);
73+
// Assert
74+
assertFalse(resBool);
75+
}
76+
77+
function testDetectTransferRestrictionTO() public {
78+
// Arrange
79+
vm.prank(DEFAULT_ADMIN_ADDRESS);
80+
ruleBlacklist.addAddress(ADDRESS2);
81+
// Act
82+
resUint8 = ruleBlacklist.detectTransferRestriction(ADDRESS1, ADDRESS2, 20);
83+
84+
// With tokenId
85+
resUint8 = ruleBlacklist.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
86+
// Assert
87+
assertEq(resUint8, CODE_ADDRESS_TO_IS_BLACKLISTED);
88+
89+
// Act
90+
resBool = ruleBlacklist.canTransfer(ADDRESS1, ADDRESS2, 20);
91+
// Assert
92+
assertFalse(resBool);
93+
94+
// Act
95+
resBool = ruleBlacklist.canTransfer(ADDRESS1, ADDRESS2, 0, 20);
96+
// Assert
97+
assertFalse(resBool);
98+
}
2599
}

test/RuleSanctionList/RuleSanctionListTest.t.sol

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,71 @@ contract RuleSanctionlistTest is Test, HelperContract {
5959
// ADDRESS1 -> ADDRESS2
6060
resBool = ruleSanctionList.canTransfer(ADDRESS1, ADDRESS2, 20);
6161
assertEq(resBool, true);
62+
resBool = ruleSanctionList.canTransfer(ADDRESS1, ADDRESS2, 0, 20);
63+
assertEq(resBool, true);
6264
// ADDRESS2 -> ADDRESS1
6365
resBool = ruleSanctionList.canTransfer(ADDRESS2, ADDRESS1, 20);
6466
assertEq(resBool, true);
67+
resBool = ruleSanctionList.canTransfer(ADDRESS2, ADDRESS1, 0, 20);
68+
assertEq(resBool, true);
6569
}
6670

6771
function testTransferFromDetectedAsInvalid() public {
6872
// Act
6973
resBool = ruleSanctionList.canTransfer(ATTACKER, ADDRESS2, 20);
7074
// Assert
7175
assertFalse(resBool);
76+
77+
// Act
78+
resBool = ruleSanctionList.canTransfer(ATTACKER, ADDRESS2, 0, 20);
79+
// Assert
80+
assertFalse(resBool);
7281
}
7382

7483
function testTransferToDetectedAsInvalid() public {
7584
// Act
7685
resBool = ruleSanctionList.canTransfer(ADDRESS1, ATTACKER, 20);
7786
// Assert
7887
assertFalse(resBool);
88+
// Act
89+
resBool = ruleSanctionList.canTransfer(ADDRESS1, ATTACKER, 0, 20);
90+
// Assert
91+
assertFalse(resBool);
7992
}
8093

8194
function testDetectTransferRestrictionFrom() public {
8295
// Act
8396
resUint8 = ruleSanctionList.detectTransferRestriction(ATTACKER, ADDRESS2, 20);
8497
// Assert
8598
assertEq(resUint8, CODE_ADDRESS_FROM_IS_SANCTIONED);
99+
100+
// Act
101+
resUint8 = ruleSanctionList.detectTransferRestriction(ATTACKER, ADDRESS2, 0, 20);
102+
// Assert
103+
assertEq(resUint8, CODE_ADDRESS_FROM_IS_SANCTIONED);
86104
}
87105

88106
function testDetectTransferRestrictionTo() public {
89107
// Act
90108
resUint8 = ruleSanctionList.detectTransferRestriction(ADDRESS1, ATTACKER, 20);
91109
// Assert
92110
assertEq(resUint8, CODE_ADDRESS_TO_IS_SANCTIONED);
111+
112+
// Act
113+
resUint8 = ruleSanctionList.detectTransferRestriction(ADDRESS1, ATTACKER, 0, 20);
114+
// Assert
115+
assertEq(resUint8, CODE_ADDRESS_TO_IS_SANCTIONED);
93116
}
94117

95118
function testDetectTransferRestrictionOk() public {
96119
// Act
97120
resUint8 = ruleSanctionList.detectTransferRestriction(ADDRESS1, ADDRESS2, 20);
98121
// Assert
99122
assertEq(resUint8, NO_ERROR);
123+
124+
// Act
125+
resUint8 = ruleSanctionList.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
126+
// Assert
127+
assertEq(resUint8, NO_ERROR);
100128
}
101129
}

test/RuleWhitelist/RuleWhitelist.t.sol

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ contract RuleWhitelistTest is Test, HelperContract {
117117
// ADDRESS1 -> ADDRESS2
118118
resBool = ruleWhitelist.canTransfer(ADDRESS1, ADDRESS2, 20);
119119
assertEq(resBool, true);
120+
resBool = ruleWhitelist.canTransfer(ADDRESS1, ADDRESS2, 0, 20);
121+
assertEq(resBool, true);
120122
// ADDRESS2 -> ADDRESS1
121123
resBool = ruleWhitelist.canTransfer(ADDRESS2, ADDRESS1, 20);
122124
assertEq(resBool, true);
125+
126+
resBool = ruleWhitelist.canTransfer(ADDRESS2, ADDRESS1, 0, 20);
127+
assertEq(resBool, true);
123128
}
124129

125130
function testTransferDetectedAsInvalid() public {
@@ -172,6 +177,16 @@ contract RuleWhitelistTest is Test, HelperContract {
172177
resUint8 = ruleWhitelist.detectTransferRestriction(ADDRESS1, ADDRESS2, 20);
173178
// Assert
174179
assertEq(resUint8, CODE_ADDRESS_TO_NOT_WHITELISTED);
180+
181+
// With tokenId
182+
resUint8 = ruleWhitelist.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
183+
// Assert
184+
assertEq(resUint8, CODE_ADDRESS_TO_NOT_WHITELISTED);
185+
186+
// With tokenId
187+
resUint8 = ruleWhitelist.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
188+
// Assert
189+
assertEq(resUint8, CODE_ADDRESS_TO_NOT_WHITELISTED);
175190
}
176191

177192
function testDetectTransferRestrictionOk() public {
@@ -184,5 +199,15 @@ contract RuleWhitelistTest is Test, HelperContract {
184199
resUint8 = ruleWhitelist.detectTransferRestriction(ADDRESS1, ADDRESS2, 20);
185200
// Assert
186201
assertEq(resUint8, NO_ERROR);
202+
203+
// With tokenId
204+
resUint8 = ruleWhitelist.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
205+
// Assert
206+
assertEq(resUint8, NO_ERROR);
207+
208+
// With tokenId
209+
resUint8 = ruleWhitelist.detectTransferRestriction(ADDRESS1, ADDRESS2, 0, 20);
210+
// Assert
211+
assertEq(resUint8, NO_ERROR);
187212
}
188213
}

test/RuleWhitelist/RuleWhitelistAdd.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ contract RuleWhitelistAddTest is Test, HelperContract {
4040
function testaddAddress() public {
4141
// Act
4242
vm.prank(WHITELIST_OPERATOR_ADDRESS);
43-
emit AddAddress(ADDRESS1);
43+
emit IAddressList.AddAddress(ADDRESS1);
4444
ruleWhitelist.addAddress(ADDRESS1);
4545

4646
// Assert
@@ -75,7 +75,7 @@ contract RuleWhitelistAddTest is Test, HelperContract {
7575

7676
// Act
7777
vm.prank(WHITELIST_OPERATOR_ADDRESS);
78-
emit AddAddress(address(0x0));
78+
emit IAddressList.AddAddress(address(0x0));
7979
ruleWhitelist.addAddress(address(0x0));
8080

8181
// Assert
@@ -95,7 +95,7 @@ contract RuleWhitelistAddTest is Test, HelperContract {
9595

9696
// Act
9797
vm.prank(WHITELIST_OPERATOR_ADDRESS);
98-
emit AddAddresses(whitelist);
98+
emit IAddressList.AddAddresses(whitelist);
9999
(resCallBool,) = address(ruleWhitelist).call(abi.encodeWithSignature("addAddresses(address[])", whitelist));
100100

101101
// Assert - Main

test/RuleWhitelist/RuleWhitelistRemove.t.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ contract RuleWhitelistRemoveTest is Test, HelperContract {
1919
whitelist[0] = ADDRESS1;
2020
whitelist[1] = ADDRESS2;
2121
vm.prank(WHITELIST_OPERATOR_ADDRESS);
22-
emit AddAddresses(whitelist);
22+
emit IAddressList.AddAddresses(whitelist);
2323
(resCallBool,) = address(ruleWhitelist).call(abi.encodeWithSignature("addAddresses(address[])", whitelist));
2424
// Assert
2525
resUint256 = ruleWhitelist.listedAddressCount();
@@ -42,7 +42,7 @@ contract RuleWhitelistRemoveTest is Test, HelperContract {
4242

4343
// Act
4444
vm.prank(WHITELIST_OPERATOR_ADDRESS);
45-
emit RemoveAddress(ADDRESS1);
45+
emit IAddressList.RemoveAddress(ADDRESS1);
4646
ruleWhitelist.removeAddress(ADDRESS1);
4747

4848
// Assert
@@ -68,7 +68,7 @@ contract RuleWhitelistRemoveTest is Test, HelperContract {
6868

6969
// Act
7070
vm.prank(WHITELIST_OPERATOR_ADDRESS);
71-
emit RemoveAddresses(whitelist);
71+
emit IAddressList.RemoveAddresses(whitelist);
7272
(resCallBool,) = address(ruleWhitelist).call(abi.encodeWithSignature("removeAddresses(address[])", whitelist));
7373
// Assert
7474
assertEq(resCallBool, true);
@@ -88,7 +88,7 @@ contract RuleWhitelistRemoveTest is Test, HelperContract {
8888

8989
// Act
9090
vm.prank(WHITELIST_OPERATOR_ADDRESS);
91-
emit RemoveAddress(ADDRESS1);
91+
emit IAddressList.RemoveAddress(ADDRESS1);
9292
ruleWhitelist.removeAddress(ADDRESS1);
9393

9494
// Assert
@@ -109,7 +109,7 @@ contract RuleWhitelistRemoveTest is Test, HelperContract {
109109

110110
// Act
111111
vm.prank(WHITELIST_OPERATOR_ADDRESS);
112-
emit RemoveAddresses(whitelistRemove);
112+
emit IAddressList.RemoveAddresses(whitelistRemove);
113113
(resCallBool,) =
114114
address(ruleWhitelist).call(abi.encodeWithSignature("removeAddresses(address[])", whitelistRemove));
115115
// Assert

0 commit comments

Comments
 (0)