Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoreliovlabs committed May 31, 2024
1 parent 564165e commit ac23981
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rskj-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ rpc {
},
trace {
version: "1.0",
enabled: "true"
enabled: "false"
},
rsk {
version: "1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,44 @@ void executeContractWithCreate2() throws Exception {
Assertions.assertEquals("\"create2\"", oresult.get("action").get("creationMethod").toString());
}

@Test
void executedContractWithDelegateCallToNonExistentContract() throws Exception {
DslParser parser = DslParser.fromResource("dsl/delegatecall02.txt");
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);

WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);

Account delegateCallAccount = world.getAccountByName("delegatecall");
Account delegatedAccount = world.getAccountByName("delegated");

Assertions.assertNotNull(delegateCallAccount);
Assertions.assertNotNull(delegatedAccount);

Transaction transaction = world.getTransactionByName("tx01");

TraceModuleImpl traceModule = new TraceModuleImpl(world.getBlockChain(), world.getBlockStore(), receiptStore, world.getBlockExecutor(), null, world.getBlockTxSignatureCache());

JsonNode result = traceModule.traceTransaction(transaction.getHash().toJsonString());

Assertions.assertNotNull(result);
Assertions.assertTrue(result.isArray());

ArrayNode aresult = (ArrayNode)result;

Assertions.assertEquals(2, aresult.size());
Assertions.assertTrue(result.get(0).isObject());

ObjectNode oresult = (ObjectNode)result.get(1);

Assertions.assertNotNull(oresult.get("action"));
Assertions.assertNotNull(oresult.get("action").get("callType"));
Assertions.assertEquals("\"delegatecall\"", oresult.get("action").get("callType").toString());
Assertions.assertEquals("\"" + delegatedAccount.getAddress().toJsonString() + "\"", oresult.get("action").get("to").toString());
Assertions.assertEquals("\"" + delegateCallAccount.getAddress().toJsonString() + "\"", oresult.get("action").get("from").toString());
}

private static World executeMultiContract(ReceiptStore receiptStore) throws DslProcessorException, FileNotFoundException {
DslParser parser = DslParser.fromResource("dsl/contracts08.txt");
World world = new World(receiptStore);
Expand Down
40 changes: 40 additions & 0 deletions rskj-core/src/test/resources/dsl/delegatecall02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

account_new acc1 10000000

# account with no contract code

account_new delegated 0

# contract account with delegate call

# code
# PUSH1 0x00 (output data size)
# PUSH1 0x00 (output data offset)
# PUSH1 0x00 (input data size)
# PUSH1 0x00 (input data offset)
# PUSH20 <delegated contract address>
# PUSH2 0x1000 (gas to use)
# DELEGATECALL
# STOP

account_new delegatecall 0 600060006000600073[delegated]611000f400

# invoke delegatecall contract

transaction_build tx01
sender acc1
receiver delegatecall
value 0
gas 1200000
build

block_build b01
parent g00
transactions tx01
build

block_connect b01

# Assert best block
assert_best b01

0 comments on commit ac23981

Please # to comment.