Skip to content

Commit

Permalink
Adding tests to validate the failure if we don't have enough gas to c…
Browse files Browse the repository at this point in the history
…over initCode
  • Loading branch information
fmacleal committed Aug 8, 2024
1 parent 9ff698a commit e561020
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class TransactionExecutorInitCodeSizeDslTest {

@Test
void testInitCodeSizeValidation() throws FileNotFoundException, DslProcessorException {
void testInitCodeSizeValidationSuccess() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/initcode_rskip438/tx_test_success_rskip_activated.txt");
World world = new World();

Expand All @@ -47,6 +47,40 @@ void testInitCodeSizeValidation() throws FileNotFoundException, DslProcessorExce
Assertions.assertEquals(1, bestBlock.getTransactionsList().size());
}

@Test
void testInitCodeSizeValidationFailsDueNotEnoughGas() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/initcode_rskip438/tx_test_just_enough_gas.txt");
World world = new World();

WorldDslProcessor processor = new WorldDslProcessor(world);

processor.processCommands(parser);

Transaction contractCreationTransaction = world.getTransactionByName("txCreateContract");
Assertions.assertNotNull(contractCreationTransaction);
Block bestBlock = world.getBlockByName("b01");
Assertions.assertEquals(0, bestBlock.getTransactionsList().size());
}

@Test
void testInitCodeSizeValidationDoesntFailDueNotEnoughGasIfRSKIPNotActivated() throws FileNotFoundException, DslProcessorException {
TestSystemProperties rskip438Disabled = new TestSystemProperties(rawConfig ->
rawConfig.withValue("blockchain.config.hardforkActivationHeights.lovell700", ConfigValueFactory.fromAnyRef(-1))
);

DslParser parser = DslParser.fromResource("dsl/initcode_rskip438/tx_test_just_enough_gas_without_rskip_activated.txt");
World world = new World(rskip438Disabled);

WorldDslProcessor processor = new WorldDslProcessor(world);

processor.processCommands(parser);

Transaction contractCreationTransaction = world.getTransactionByName("txCreateContract");
Assertions.assertNotNull(contractCreationTransaction);
Block bestBlock = world.getBlockByName("b01");
Assertions.assertEquals(1, bestBlock.getTransactionsList().size());
}

@Test
void testInitCodeSizeValidationWithRSKIP438Deactivated() throws FileNotFoundException, DslProcessorException {
TestSystemProperties rskip438Disabled = new TestSystemProperties(rawConfig ->
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ contract Storage {

end

account_new acc1 10000000
account_new acc1 4800000

# deploy contract compiled with 0.8.20
# deploy contract compiled with 0.8.20
transaction_build txCreateContract
sender acc1
receiverAddress 00
Expand All @@ -42,4 +42,4 @@ block_connect b01
assert_best b01

# check sender balance, it should pay the total cost of contract creation WITH initcode size cost
assert_balance acc1 5530899
assert_balance acc1 330899

0 comments on commit e561020

Please sign in to comment.