Skip to content

Commit

Permalink
Starting to add more context calls tests for the tload/tstore
Browse files Browse the repository at this point in the history
  • Loading branch information
fmacleal committed Oct 25, 2024
1 parent 8d1b93c commit 7038543
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
2 changes: 0 additions & 2 deletions rskj-core/src/main/java/org/ethereum/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ void testTransientStorageTestsEip1153BasicScenarios() throws FileNotFoundExcepti
Assertions.assertEquals(4, TransactionReceiptUtil.getEventCount(txReceipt, "OK", null));
}

@Test
void testTransientStorageTestsCreateContextsOnlyConstructorCode() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/transaction_storage_rskip446/tload_tstore_create_context_only_constructor_code.txt");
World world = new World();
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);

String mainContractTransientStorageCreationTxName = "txTestTransientStorageContract";
TransactionReceipt txReceipt = assertTransactionReceiptWithStatus(world, mainContractTransientStorageCreationTxName, "b01", true);
Assertions.assertEquals(2, TransactionReceiptUtil.getEventCount(txReceipt, "OK", null));
}

private static TransactionReceipt assertTransactionReceiptWithStatus(World world, String txName, String blockName, boolean withSuccess) {
Transaction txCreation = world.getTransactionByName(txName);
assertNotNull(txCreation);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
comment

// CONTRACT CODE
pragma solidity ^0.8.24;

contract TestsTransientStorageCreateContextsOnlyConstructorCode {

constructor() {
bytes32 valueLoadedInitially;
bytes32 valueLoadedAfterStore;
assembly{
valueLoadedInitially := tload(0)
tstore(0,0x0000000000000000000000000000000100000000000000000000000000000001)
valueLoadedAfterStore := tload(0)
}
if(valueLoadedInitially == 0x00){
emit OK();
} else {
emit ERROR(valueLoadedInitially);
}

if(valueLoadedAfterStore == 0x0000000000000000000000000000000100000000000000000000000000000001){
emit OK();
} else {
emit ERROR(valueLoadedAfterStore);
}
}

event OK();
event ERROR(bytes32);
}

// CONTRACT BYTECODE

TestsTransientStorageCreateContextsOnlyConstructorCode: 608060405234801561000f575f80fd5b505f805f5c91507001000000000000000000000000000000015f5d5f5c90505f801b8203610068577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16100a0565b7f2fe0d3bd8bbb632441eefda46ec52f1ddda3a9e827d14c40f422037320f28bd9826040516100979190610142565b60405180910390a15b7001000000000000000000000000000000015f1b81036100eb577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a1610123565b7f2fe0d3bd8bbb632441eefda46ec52f1ddda3a9e827d14c40f422037320f28bd98160405161011a9190610142565b60405180910390a15b505061015b565b5f819050919050565b61013c8161012a565b82525050565b5f6020820190506101555f830184610133565b92915050565b603e806101675f395ff3fe60806040525f80fdfea2646970667358221220c3c06d3ce43439437bdc0d04739df150a62dcb18dc5af99be6058c5c452435d964736f6c634300081a0033

end


# Create and fund new account
account_new acc1 10000000

# Create transaction to deploy TestTransientStorage contract
transaction_build txTestTransientStorageContract
sender acc1
receiverAddress 00
value 0
data 608060405234801561000f575f80fd5b505f805f5c91507001000000000000000000000000000000015f5d5f5c90505f801b8203610068577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16100a0565b7f2fe0d3bd8bbb632441eefda46ec52f1ddda3a9e827d14c40f422037320f28bd9826040516100979190610142565b60405180910390a15b7001000000000000000000000000000000015f1b81036100eb577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a1610123565b7f2fe0d3bd8bbb632441eefda46ec52f1ddda3a9e827d14c40f422037320f28bd98160405161011a9190610142565b60405180910390a15b505061015b565b5f819050919050565b61013c8161012a565b82525050565b5f6020820190506101555f830184610133565b92915050565b603e806101675f395ff3fe60806040525f80fdfea2646970667358221220c3c06d3ce43439437bdc0d04739df150a62dcb18dc5af99be6058c5c452435d964736f6c634300081a0033
gas 1000000
build

# Create block to hold txTestTransientStorageContract transaction
block_build b01
parent g00
transactions txTestTransientStorageContract
build

# Connect block
block_connect b01

# Check b01 is best block
assert_best b01

0 comments on commit 7038543

Please sign in to comment.