Skip to content

Commit

Permalink
test: 11134 - Create hapi tests for extCode operations for system acc…
Browse files Browse the repository at this point in the history
…ounts (#11278)

Signed-off-by: Ivan Ivanov <ivanivanov.ii726@gmail.com>
Signed-off-by: Timo Brandstätter <timo@swirldslabs.com>
  • Loading branch information
0xivanov authored and timo0 committed Feb 16, 2024
1 parent aaadb1f commit b233b2e
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public class Evm46ValidationSuite extends HapiSuite {
private static final String DYNAMIC_EVM_PROPERTY = "contracts.evm.version.dynamic";
private static final String EVM_VERSION_046 = "v0.46";
private static final String BALANCE_OF = "balanceOf";

public static final List<Long> nonExistingSystemAccounts =
List.of(0L, 1L, 9L, 10L, 358L, 359L, 360L, 361L, 750L, 751L);
public static final List<Long> existingSystemAccounts = List.of(999L, 1000L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
import static com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.FULLY_NONDETERMINISTIC;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_FUNCTION_PARAMETERS;
import static com.hedera.services.bdd.suites.contract.Utils.mirrorAddrWith;
import static com.hedera.services.bdd.suites.contract.evm.Evm46ValidationSuite.systemAccounts;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS;

import com.google.protobuf.ByteString;
import com.hedera.services.bdd.junit.HapiTest;
import com.hedera.services.bdd.junit.HapiTestSuite;
import com.hedera.services.bdd.spec.HapiSpec;
import com.hedera.services.bdd.spec.HapiSpecOperation;
import com.hedera.services.bdd.suites.HapiSuite;
import java.util.List;
import org.apache.logging.log4j.LogManager;
Expand All @@ -56,7 +60,7 @@ public static void main(String[] args) {

@Override
public List<HapiSpec> getSpecsInSuite() {
return List.of(verifiesExistence());
return List.of(verifiesExistence(), testExtCodeCopyWithSystemAccounts());
}

@Override
Expand Down Expand Up @@ -123,6 +127,40 @@ contract, codeCopyOf, asHeadlongAddress(contractAddress))
}));
}

@HapiTest
HapiSpec testExtCodeCopyWithSystemAccounts() {
final var contract = "ExtCodeOperationsChecker";
final var emptyBytecode = ByteString.EMPTY;
final var codeCopyOf = "codeCopyOf";
final var account = "account";
final HapiSpecOperation[] opsArray = new HapiSpecOperation[systemAccounts.size() * 2];

for (int i = 0; i < systemAccounts.size(); i++) {
// add contract call for all accounts in the list
opsArray[i] = contractCall(contract, codeCopyOf, mirrorAddrWith(systemAccounts.get(i)))
.hasKnownStatus(SUCCESS);

// add contract call local for all accounts in the list
int finalI = i;
opsArray[systemAccounts.size() + i] = withOpContext((spec, opLog) -> {
final var accountSolidityAddress = mirrorAddrWith(systemAccounts.get(finalI));

final var accountCodeCallLocal = contractCallLocal(contract, codeCopyOf, accountSolidityAddress)
.saveResultTo("accountCode");
allRunFor(spec, accountCodeCallLocal);

final var accountCode = spec.registry().getBytes("accountCode");

Assertions.assertArrayEquals(emptyBytecode.toByteArray(), accountCode);
});
}

return defaultHapiSpec("testExtCodeCopyWithSystemAccounts", NONDETERMINISTIC_FUNCTION_PARAMETERS)
.given(uploadInitCode(contract), contractCreate(contract), cryptoCreate(account))
.when()
.then(opsArray);
}

@Override
protected Logger getResultsLogger() {
return LOG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
import static com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_FUNCTION_PARAMETERS;
import static com.hedera.services.bdd.suites.contract.Utils.FunctionType.FUNCTION;
import static com.hedera.services.bdd.suites.contract.Utils.getABIFor;
import static com.hedera.services.bdd.suites.contract.Utils.mirrorAddrWith;
import static com.hedera.services.bdd.suites.contract.evm.Evm46ValidationSuite.systemAccounts;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS;

import com.google.protobuf.ByteString;
import com.hedera.services.bdd.junit.HapiTest;
import com.hedera.services.bdd.junit.HapiTestSuite;
import com.hedera.services.bdd.spec.HapiSpec;
import com.hedera.services.bdd.spec.HapiSpecOperation;
import com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts;
import com.hedera.services.bdd.suites.HapiSuite;
import java.util.List;
import org.apache.logging.log4j.LogManager;
Expand All @@ -58,7 +64,7 @@ public static void main(String[] args) {

@Override
public List<HapiSpec> getSpecsInSuite() {
return List.of(verifiesExistence());
return List.of(verifiesExistence(), testExtCodeHashWithSystemAccounts());
}

@Override
Expand Down Expand Up @@ -124,6 +130,33 @@ contract, hashOf, asHeadlongAddress(contractAddress))
}));
}

@HapiTest
HapiSpec testExtCodeHashWithSystemAccounts() {
final var contract = "ExtCodeOperationsChecker";
final var hashOf = "hashOf";
final String account = "account";
final HapiSpecOperation[] opsArray = new HapiSpecOperation[systemAccounts.size() * 2];

for (int i = 0; i < systemAccounts.size(); i++) {
// add contract call for all accounts in the list
opsArray[i] = contractCall(contract, hashOf, mirrorAddrWith(systemAccounts.get(i)))
.hasKnownStatus(SUCCESS);

// add contract call local for all accounts in the list
opsArray[systemAccounts.size() + i] = contractCallLocal(
contract, hashOf, mirrorAddrWith(systemAccounts.get(i)))
.has(ContractFnResultAsserts.resultWith()
.resultThruAbi(
getABIFor(FUNCTION, hashOf, contract),
ContractFnResultAsserts.isLiteralResult(new Object[] {new byte[32]})));
}

return defaultHapiSpec("testExtCodeHashWithSystemAccounts", NONDETERMINISTIC_FUNCTION_PARAMETERS)
.given(uploadInitCode(contract), contractCreate(contract), cryptoCreate(account))
.when()
.then(opsArray);
}

@Override
protected Logger getResultsLogger() {
return LOG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_FUNCTION_PARAMETERS;
import static com.hedera.services.bdd.suites.contract.Utils.FunctionType.FUNCTION;
import static com.hedera.services.bdd.suites.contract.Utils.getABIFor;
import static com.hedera.services.bdd.suites.contract.Utils.mirrorAddrWith;
import static com.hedera.services.bdd.suites.contract.evm.Evm46ValidationSuite.systemAccounts;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS;

import com.hedera.services.bdd.junit.HapiTest;
import com.hedera.services.bdd.junit.HapiTestSuite;
import com.hedera.services.bdd.spec.HapiSpec;
import com.hedera.services.bdd.spec.HapiSpecOperation;
import com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts;
import com.hedera.services.bdd.suites.HapiSuite;
import java.math.BigInteger;
Expand All @@ -62,7 +65,7 @@ public static void main(String[] args) {

@Override
public List<HapiSpec> getSpecsInSuite() {
return List.of(verifiesExistence());
return List.of(verifiesExistence(), testExtCodeSizeWithSystemAccounts());
}

@Override
Expand Down Expand Up @@ -128,6 +131,33 @@ contract, sizeOf, asHeadlongAddress(contractAddress))
}));
}

@HapiTest
HapiSpec testExtCodeSizeWithSystemAccounts() {
final var contract = "ExtCodeOperationsChecker";
final var sizeOf = "sizeOf";
final var account = "account";
final HapiSpecOperation[] opsArray = new HapiSpecOperation[systemAccounts.size() * 2];

for (int i = 0; i < systemAccounts.size(); i++) {
// add contract call for all accounts in the list
opsArray[i] = contractCall(contract, sizeOf, mirrorAddrWith(systemAccounts.get(i)))
.hasKnownStatus(SUCCESS);

// add contract call local for all accounts in the list
opsArray[systemAccounts.size() + i] = contractCallLocal(
contract, sizeOf, mirrorAddrWith(systemAccounts.get(i)))
.has(ContractFnResultAsserts.resultWith()
.resultThruAbi(
getABIFor(FUNCTION, sizeOf, contract),
ContractFnResultAsserts.isLiteralResult(new Object[] {BigInteger.valueOf(0L)})));
}

return defaultHapiSpec("testExtCodeSizeWithSystemAccounts", NONDETERMINISTIC_FUNCTION_PARAMETERS)
.given(uploadInitCode(contract), contractCreate(contract), cryptoCreate(account))
.when()
.then(opsArray);
}

@Override
protected Logger getResultsLogger() {
return LOG;
Expand Down

0 comments on commit b233b2e

Please sign in to comment.