Skip to content

Commit

Permalink
feat(pte): fix unit tests after merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed Sep 26, 2024
1 parent 3059c4c commit ecbb0ad
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 69 deletions.
58 changes: 25 additions & 33 deletions rskj-core/src/test/java/co/rsk/core/bc/BlockExecutorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,23 @@
*/
public class BlockExecutorTest {
private static final byte[] EMPTY_TRIE_HASH = sha3(RLP.encodeElement(EMPTY_BYTE_ARRAY));
private static final TestSystemProperties CONFIG = new TestSystemProperties();
private static final ActivationConfig activationConfig = spy(CONFIG.getActivationConfig());
private static final BlockFactory BLOCK_FACTORY = new BlockFactory(activationConfig);
public static final boolean RSKIP_126_IS_ACTIVE = true;
private final long MIN_SEQUENTIAL_SET_GAS_LIMIT = Constants.regtest().getMinSequentialSetGasLimit();
private static final boolean RSKIP_126_IS_ACTIVE = true;
private static final long MIN_SEQUENTIAL_SET_GAS_LIMIT = Constants.regtest().getMinSequentialSetGasLimit();

private final TestSystemProperties config = new TestSystemProperties();
private final ActivationConfig activationConfig = spy(config.getActivationConfig());
private final BlockFactory BLOCK_FACTORY = new BlockFactory(activationConfig);

@TempDir
public Path tempDir;

private Blockchain blockchain;
private TrieStore trieStore;
private RepositorySnapshot repository;
private RskSystemProperties cfg;

@BeforeEach
public void setUp() {
cfg = spy(CONFIG);
doReturn(activationConfig).when(cfg).getActivationConfig();
RskTestFactory objects = new RskTestFactory(tempDir, CONFIG);
RskTestFactory objects = new RskTestFactory(tempDir, config);
blockchain = objects.getBlockchain();
trieStore = objects.getTrieStore();
repository = objects.getRepositoryLocator().snapshotAt(blockchain.getBestBlock().getHeader());
Expand Down Expand Up @@ -362,7 +360,7 @@ private Block createBlockWithExcludedTransaction(boolean withRemasc, boolean act
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(account2.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx3.sign(account.getEcKey().getPrivKeyBytes());
Expand All @@ -373,7 +371,7 @@ private Block createBlockWithExcludedTransaction(boolean withRemasc, boolean act
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(account2.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx1.sign(account3.getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -451,7 +449,7 @@ void executeBlockWithTxThatMakesBlockInvalidSenderHasNoBalance(boolean activeRsk
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(account2.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx3.sign(account.getEcKey().getPrivKeyBytes());
Expand All @@ -462,7 +460,7 @@ void executeBlockWithTxThatMakesBlockInvalidSenderHasNoBalance(boolean activeRsk
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(account2.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx1.sign(account3.getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -748,7 +746,7 @@ void whenExecuteATxWithGasLimitExceedingSublistGasLimitShouldNotBeInlcuded(boole
.gasPrice(BigInteger.ONE)
.gasLimit(parent.getGasLimit())
.destination(receiver.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx.sign(sender.getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -877,13 +875,7 @@ void validateStateRootWithRskip126DisabledAndValidStateRoot(boolean activeRskip1
BlockResult blockResult = new BlockResult(block, Collections.emptyList(), Collections.emptyList(), new short[0], 0,
Coin.ZERO, trie);

// RskSystemProperties cfg = spy(CONFIG);

ActivationConfig activationConfig = spy(cfg.getActivationConfig());
doReturn(false).when(activationConfig).isActive(eq(RSKIP126), anyLong());
doReturn(activationConfig).when(cfg).getActivationConfig();

BlockExecutor executor = buildBlockExecutor(trieStore, cfg, activeRskip144, false);
BlockExecutor executor = buildBlockExecutor(trieStore, activeRskip144, false);

short[] expectedEdges = activeRskip144 ? new short[0] : null;

Expand Down Expand Up @@ -1016,7 +1008,7 @@ void invalidBlockBadLogsBloom(boolean activeRskip144) {
Assertions.assertFalse(executor.executeAndValidate(block, parent.getHeader()));
}

private static TestObjects generateBlockWithOneTransaction(Boolean activeRskip144, boolean rskip126IsActive) {
private TestObjects generateBlockWithOneTransaction(Boolean activeRskip144, boolean rskip126IsActive) {
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
Repository repository = new MutableRepository(trieStore, new Trie(trieStore));

Expand All @@ -1037,7 +1029,7 @@ private static TestObjects generateBlockWithOneTransaction(Boolean activeRskip14
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(account2.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx1.sign(account.getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -1084,7 +1076,7 @@ private Block getBlockWithOneTransaction() {
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(account2.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx.sign(account.getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -1117,7 +1109,7 @@ private Block getBlockWithTwoTransactions() {
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(account2.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx.sign(account.getEcKey().getPrivKeyBytes());
Expand All @@ -1127,7 +1119,7 @@ private Block getBlockWithTwoTransactions() {
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(account2.getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx1.sign(account.getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -1161,7 +1153,7 @@ private Block getBlockWithTwoDependentTransactions(short[] edges) {
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(accounts.get((i + 1) % 2).getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx.sign(accounts.get(i).getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -1203,7 +1195,7 @@ private Block getBlockWithTenTransactions(short[] edges) {
.gasPrice(BigInteger.ONE)
.gasLimit(BigInteger.valueOf(21000))
.destination(accounts.get(i + nTxs).getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx.sign(accounts.get(i).getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -1244,7 +1236,7 @@ private Block getBlockWithNIndependentTransactions(int numberOfTxs, BigInteger t
.gasPrice(BigInteger.ONE)
.gasLimit(txGasLimit)
.destination(accounts.get(i + numberOfTxs).getAddress())
.chainId(CONFIG.getNetworkConstants().getChainId())
.chainId(config.getNetworkConstants().getChainId())
.value(BigInteger.TEN)
.build();
tx.sign(accounts.get(i).getEcKey().getPrivKeyBytes());
Expand Down Expand Up @@ -1413,7 +1405,7 @@ public TestObjects generateBlockWithOneStrangeTransaction(int strangeTransaction
private byte[] calculateTxTrieRoot(List<Transaction> transactions, long blockNumber) {
return BlockHashesHelper.getTxTrieRoot(
transactions,
CONFIG.getActivationConfig().isActive(ConsensusRule.RSKIP126, blockNumber)
config.getActivationConfig().isActive(ConsensusRule.RSKIP126, blockNumber)
);
}

Expand Down Expand Up @@ -1455,11 +1447,11 @@ private static byte[] sha3(byte[] input) {
return digest.digest();
}

private static BlockExecutor buildBlockExecutor(TrieStore store, Boolean activeRskip144, boolean rskip126IsActive) {
return buildBlockExecutor(store, CONFIG, activeRskip144, rskip126IsActive);
private BlockExecutor buildBlockExecutor(TrieStore store, Boolean activeRskip144, boolean rskip126IsActive) {
return buildBlockExecutor(store, config, activeRskip144, rskip126IsActive);
}

private static BlockExecutor buildBlockExecutor(TrieStore store, RskSystemProperties config, Boolean activeRskip144, Boolean activeRskip126) {
private BlockExecutor buildBlockExecutor(TrieStore store, RskSystemProperties config, Boolean activeRskip144, Boolean activeRskip126) {
RskSystemProperties cfg = spy(config);
doReturn(activationConfig).when(cfg).getActivationConfig();
doReturn(activeRskip144).when(activationConfig).isActive(eq(RSKIP144), anyLong());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ transaction_build txCreateContractFactory
receiverAddress 00
value 0
data 608060405234801561001057600080fd5b50610cde806100206000396000f3fe6080604052600436106200002c5760003560e01c8063490af4231462000031578063fdaaa16f1462000067575b600080fd5b6200004f6004803603810190620000499190620002c1565b620000ab565b6040516200005e919062000357565b60405180910390f35b3480156200007457600080fd5b506200009360048036038101906200008d9190620002c1565b620000fb565b604051620000a2919062000357565b60405180910390f35b600080600160001b90508083604051620000c5906200013d565b620000d19190620003fd565b8190604051809103906000f5905080158015620000f2573d6000803e3d6000fd5b50915050919050565b6000816040516200010c906200013d565b620001189190620003fd565b604051809103906000f08015801562000135573d6000803e3d6000fd5b509050919050565b610887806200042283390190565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620001b48262000169565b810181811067ffffffffffffffff82111715620001d657620001d56200017a565b5b80604052505050565b6000620001eb6200014b565b9050620001f98282620001a9565b919050565b600067ffffffffffffffff8211156200021c576200021b6200017a565b5b620002278262000169565b9050602081019050919050565b82818337600083830152505050565b60006200025a6200025484620001fe565b620001df565b90508281526020810184848401111562000279576200027862000164565b5b6200028684828562000234565b509392505050565b600082601f830112620002a657620002a56200015f565b5b8135620002b884826020860162000243565b91505092915050565b600060208284031215620002da57620002d962000155565b5b600082013567ffffffffffffffff811115620002fb57620002fa6200015a565b5b62000309848285016200028e565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006200033f8262000312565b9050919050565b620003518162000332565b82525050565b60006020820190506200036e600083018462000346565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015620003b057808201518184015260208101905062000393565b60008484015250505050565b6000620003c98262000374565b620003d581856200037f565b9350620003e781856020860162000390565b620003f28162000169565b840191505092915050565b60006020820190508181036000830152620004198184620003bc565b90509291505056fe60806040523480156200001157600080fd5b506040516200088738038062000887833981810160405281019062000037919062000223565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060019081620000889190620004bf565b5050620005a6565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620000f982620000ae565b810181811067ffffffffffffffff821117156200011b576200011a620000bf565b5b80604052505050565b60006200013062000090565b90506200013e8282620000ee565b919050565b600067ffffffffffffffff821115620001615762000160620000bf565b5b6200016c82620000ae565b9050602081019050919050565b60005b83811015620001995780820151818401526020810190506200017c565b60008484015250505050565b6000620001bc620001b68462000143565b62000124565b905082815260208101848484011115620001db57620001da620000a9565b5b620001e884828562000179565b509392505050565b600082601f830112620002085762000207620000a4565b5b81516200021a848260208601620001a5565b91505092915050565b6000602082840312156200023c576200023b6200009a565b5b600082015167ffffffffffffffff8111156200025d576200025c6200009f565b5b6200026b84828501620001f0565b91505092915050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680620002c757607f821691505b602082108103620002dd57620002dc6200027f565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b600060088302620003477fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000308565b62000353868362000308565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b6000620003a06200039a62000394846200036b565b62000375565b6200036b565b9050919050565b6000819050919050565b620003bc836200037f565b620003d4620003cb82620003a7565b84845462000315565b825550505050565b600090565b620003eb620003dc565b620003f8818484620003b1565b505050565b5b81811015620004205762000414600082620003e1565b600181019050620003fe565b5050565b601f8211156200046f576200043981620002e3565b6200044484620002f8565b8101602085101562000454578190505b6200046c6200046385620002f8565b830182620003fd565b50505b505050565b600082821c905092915050565b6000620004946000198460080262000474565b1980831691505092915050565b6000620004af838362000481565b9150826002028217905092915050565b620004ca8262000274565b67ffffffffffffffff811115620004e657620004e5620000bf565b5b620004f28254620002ae565b620004ff82828562000424565b600060209050601f83116001811462000537576000841562000522578287015190505b6200052e8582620004a1565b8655506200059e565b601f1984166200054786620002e3565b60005b8281101562000571578489015182556001820191506020850194506020810190506200054a565b868310156200059157848901516200058d601f89168262000481565b8355505b6001600288020188555050505b505050505050565b6102d180620005b66000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80636d4ce63c1461003b5780638da5cb5b14610059575b600080fd5b610043610077565b60405161005091906101bd565b60405180910390f35b610061610109565b60405161006e9190610220565b60405180910390f35b6060600180546100869061026a565b80601f01602080910402602001604051908101604052809291908181526020018280546100b29061026a565b80156100ff5780601f106100d4576101008083540402835291602001916100ff565b820191906000526020600020905b8154815290600101906020018083116100e257829003601f168201915b5050505050905090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081519050919050565b600082825260208201905092915050565b60005b8381101561016757808201518184015260208101905061014c565b60008484015250505050565b6000601f19601f8301169050919050565b600061018f8261012d565b6101998185610138565b93506101a9818560208601610149565b6101b281610173565b840191505092915050565b600060208201905081810360008301526101d78184610184565b905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061020a826101df565b9050919050565b61021a816101ff565b82525050565b60006020820190506102356000830184610211565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061028257607f821691505b6020821081036102955761029461023b565b5b5091905056fea264697066735822122071163cf749253f921b29799fb8f2b856a099dcdc627d7622ee7536e5e392509464736f6c63430008180033a2646970667358221220bd9fa3c126989a1d6a7a7fe44541a0bf9a4b43a3d2e12733f1208d6beaf0ede564736f6c63430008180033
gas 6500000
gas 800000
build

block_build b01
parent g00
gasLimit 6500000
transactions txCreateContractFactory
build

Expand All @@ -69,7 +68,7 @@ transaction_build txCreateContractViaOpCodeCreate2

block_build b02
parent b01
gasLimit 10000000
gasLimit 30000000
transactions txCreateContractViaOpCodeCreate2
build

Expand Down
Loading

0 comments on commit ecbb0ad

Please sign in to comment.