|
24 | 24 | import co.rsk.test.dsl.WorldDslProcessor; |
25 | 25 | import co.rsk.util.HexUtils; |
26 | 26 | import org.ethereum.core.Account; |
| 27 | +import org.ethereum.core.Block; |
27 | 28 | import org.ethereum.core.Transaction; |
28 | 29 | import org.ethereum.core.TransactionReceipt; |
29 | 30 | import org.ethereum.rpc.CallArguments; |
@@ -91,7 +92,7 @@ void testCall_getRevertReason() throws FileNotFoundException, DslProcessorExcept |
91 | 92 | } |
92 | 93 |
|
93 | 94 | @Test |
94 | | - void testCall_StateOverride_stateIsOverride() throws DslProcessorException, FileNotFoundException { |
| 95 | + void testCall_StateOverride_stateIsOverridden() throws DslProcessorException, FileNotFoundException { |
95 | 96 | // When |
96 | 97 | World world = new World(); |
97 | 98 | // given a deployed contract with stored state = 10 |
@@ -135,7 +136,7 @@ void testCall_StateOverride_stateIsOverride() throws DslProcessorException, File |
135 | 136 | * } |
136 | 137 | */ |
137 | 138 | @Test |
138 | | - void testCall_StateOverride_codeOverride() throws DslProcessorException, FileNotFoundException { |
| 139 | + void testCall_StateOverride_codeIsOverridden() throws DslProcessorException, FileNotFoundException { |
139 | 140 | // Given |
140 | 141 | // This is the runtime bytecode of the contract above to override the original contract |
141 | 142 | String runtimeByteCode = "0x6103e760005260206000f3"; |
@@ -169,7 +170,7 @@ void testCall_StateOverride_codeOverride() throws DslProcessorException, FileNot |
169 | 170 | } |
170 | 171 |
|
171 | 172 | @Test |
172 | | - void testCall_StateOverride_balanceOverride()throws DslProcessorException, FileNotFoundException { |
| 173 | + void testCall_StateOverride_balanceIsOverridden()throws DslProcessorException, FileNotFoundException { |
173 | 174 | // Given |
174 | 175 | long defaultBalance = 30000L; |
175 | 176 | World world = new World(); |
@@ -203,6 +204,69 @@ void testCall_StateOverride_balanceOverride()throws DslProcessorException, FileN |
203 | 204 | assertEquals(defaultBalance, HexUtils.jsonHexToInt(result2)); |
204 | 205 | } |
205 | 206 |
|
| 207 | + @Test |
| 208 | + void testCall_StateOverride_precompiledContractIsMoved() throws DslProcessorException, FileNotFoundException { |
| 209 | + |
| 210 | + // Given |
| 211 | + |
| 212 | + String falseInHex = "0x0000000000000000000000000000000000000000000000000000000000000000"; |
| 213 | + String trueInHex = "0x0000000000000000000000000000000000000000000000000000000000000001"; |
| 214 | + |
| 215 | + // Test Setup |
| 216 | + |
| 217 | + DslParser parser = DslParser.fromResource("dsl/eth_module/test_state_override_move_precompiled.txt"); |
| 218 | + World world = new World(); |
| 219 | + WorldDslProcessor processor = new WorldDslProcessor(world); |
| 220 | + processor.processCommands(parser); |
| 221 | + |
| 222 | + Account acc = world.getAccountByName("acc1"); |
| 223 | + RskAddress identityPrecompiledAddress = new RskAddress("0x0000000000000000000000000000000000000004"); |
| 224 | + RskAddress movePrecompiledTo = new RskAddress("0x0000000000000000000000000000000000000001"); |
| 225 | + |
| 226 | + // Test Steps |
| 227 | + |
| 228 | + // 0. Check that DatacopyCaller contract was deployed correctly |
| 229 | + Block block01 = world.getBlockByName("b01"); |
| 230 | + Assertions.assertNotNull(block01); |
| 231 | + Assertions.assertEquals(1, block01.getTransactionsList().size()); |
| 232 | + |
| 233 | + String contractAddress = world.getTransactionByName("tx01").getContractAddress().toHexString(); |
| 234 | + |
| 235 | + // 1. Check that checkOriginalDatacopyWorksAsExpected (0xb7deb48b) is executed correctly |
| 236 | + |
| 237 | + EthModule eth = EthModuleTestUtils.buildBasicEthModule(world); |
| 238 | + |
| 239 | + CallArguments args = new CallArguments(); |
| 240 | + args.setFrom(acc.getAddress().toHexString()); |
| 241 | + args.setTo("0x" + contractAddress); |
| 242 | + args.setData("0xb7deb48b"); // Call checkOriginalDatacopyWorksAsExpected() function |
| 243 | + BlockIdentifierParam blockIdentifierParam = new BlockIdentifierParam("latest"); |
| 244 | + CallArgumentsParam callArgumentsParam = TransactionFactoryHelper.toCallArgumentsParam(args); |
| 245 | + |
| 246 | + String result = eth.call(callArgumentsParam, blockIdentifierParam); |
| 247 | + assertEquals(trueInHex, result); |
| 248 | + |
| 249 | + // 2. Check that checkOverriddenDatacopyWorksAsExpected (0x1cf61a8b) returns "false" before overriding |
| 250 | + |
| 251 | + CallArguments args2 = new CallArguments(); |
| 252 | + args2.setFrom(acc.getAddress().toHexString()); |
| 253 | + args2.setTo("0x" + contractAddress); |
| 254 | + args2.setData("0x1cf61a8b"); // Call checkOverriddenDatacopyWorksAsExpected() function |
| 255 | + CallArgumentsParam callArgumentsParam2 = TransactionFactoryHelper.toCallArgumentsParam(args2); |
| 256 | + |
| 257 | + String result2 = eth.call(callArgumentsParam2, blockIdentifierParam); |
| 258 | + assertEquals(falseInHex, result2); |
| 259 | + |
| 260 | + // 3. Check that checkOverriddenDatacopyWorksAsExpected (0x1cf61a8b) returns "true" after overriding |
| 261 | + |
| 262 | + AccountOverride accountOverride = new AccountOverride(identityPrecompiledAddress); |
| 263 | + accountOverride.setMovePrecompileToAddress(movePrecompiledTo); |
| 264 | + |
| 265 | + String result3 = eth.call(callArgumentsParam2, blockIdentifierParam, List.of(accountOverride)); |
| 266 | + assertEquals(trueInHex, result3); |
| 267 | + |
| 268 | + } |
| 269 | + |
206 | 270 | private String deployContractAndGetAddressFromDsl(String dslContractPath, World world) throws DslProcessorException, FileNotFoundException{ |
207 | 271 | DslParser parser = DslParser.fromResource(dslContractPath); |
208 | 272 | WorldDslProcessor processor = new WorldDslProcessor(world); |
|
0 commit comments