Skip to content

Commit

Permalink
fix failing tests in modPrecompiled after adding fork-properties
Browse files Browse the repository at this point in the history
  • Loading branch information
beidouz committed Nov 19, 2018
1 parent 7ed73f0 commit 0dc8939
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions modAionImpl/test/org/aion/zero/impl/cli/CliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class CliTest {

private static final String configFileName = "config.xml";
private static final String genesisFileName = "genesis.json";
private static final String forkFileName = "fork.properties";

private static final String dataDirectory = "datadir";
private static final String alternativeDirectory = "random";
Expand All @@ -102,6 +103,11 @@ public class CliTest {
private static final File mainnetGenesis = new File(MAIN_CONFIG_PATH, genesisFileName);
private static final File testnetGenesis = new File(TEST_CONFIG_PATH, genesisFileName);

private static final File fork = new File(TEST_RESOURCE_DIR, forkFileName);
private static final File oldFork = new File(CONFIG_PATH, forkFileName);
private static final File mainnetFork = new File(MAIN_CONFIG_PATH, forkFileName);
private static final File testnetFork = new File(TEST_CONFIG_PATH, forkFileName);

/** @implNote set this to true to enable printing */
private static final boolean verbose = false;

Expand All @@ -117,6 +123,7 @@ public void setup() {
}
Cli.copyRecursively(config, mainnetConfig);
Cli.copyRecursively(genesis, mainnetGenesis);
Cli.copyRecursively(fork, mainnetFork);
}

if (BASE_PATH.contains(module) && !testnetConfig.exists()) {
Expand All @@ -126,6 +133,7 @@ public void setup() {
}
Cli.copyRecursively(config, mainnetConfig);
Cli.copyRecursively(genesis, testnetGenesis);
Cli.copyRecursively(fork, testnetFork);
}

cfg.resetInternal();
Expand Down
1 change: 1 addition & 0 deletions modMcf/src/org/aion/mcf/config/CfgFork.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void setProperties(Properties properties) {
}

public String getForkPropertyByNumber(final int forkNum) {
if (forkProperties == null) return null;
return forkProperties.getProperty("fork" + String.valueOf(forkNum));
}
}
5 changes: 3 additions & 2 deletions modPrecompiled/test/org/aion/precompiled/BenchmarkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.aion.mcf.vm.types.DataWord;
import org.aion.vm.ExecutionContext;
import org.aion.vm.IPrecompiledContract;
import org.aion.zero.impl.config.CfgAion;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -48,12 +49,12 @@ public class BenchmarkTest {
@Before
public void setup() {
cf = new ContractFactory();

CfgAion.inst().setForkProperties();
txHash = RandomUtils.nextBytes(32);
origin = Address.wrap(RandomUtils.nextBytes(32));
caller = origin;
blockCoinbase = Address.wrap(RandomUtils.nextBytes(32));
blockNumber = 1;
blockNumber = 2000001;
blockTimestamp = System.currentTimeMillis() / 1000;
blockNrgLimit = 5000000;
blockDifficulty = new DataWord(0x100000000L);
Expand Down
4 changes: 3 additions & 1 deletion modPrecompiled/test/org/aion/precompiled/TXHashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.aion.vm.ExecutionContext;
import org.aion.vm.ExecutionResult;
import org.aion.vm.IPrecompiledContract;
import org.aion.zero.impl.config.CfgAion;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -44,10 +45,11 @@ public class TXHashTest {

@Before
public void setUp() {
CfgAion.inst().setForkProperties();
ExecutionContext ctx = new ExecutionContext(txHash,
ContractFactory.getTxHashContractAddress(), null, null, null,
0L, null, null, 0, 0, 0, null,
0L, 0L, 0L,
2000001L, 0L, 0L,
null);

tXHashContract = new ContractFactory().getPrecompiledContract(ctx, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.aion.vm.ExecutionContext;
import org.aion.vm.ExecutionResult;
import org.aion.vm.IPrecompiledContract;
import org.aion.zero.impl.config.CfgAion;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -49,7 +50,7 @@ public class EDVerifyContractTest {
private Address caller = origin;

private Address blockCoinbase = Address.wrap(RandomUtils.nextBytes(32));
private long blockNumber = 1;
private long blockNumber = 2000001;
private long blockTimestamp = System.currentTimeMillis() / 1000;
private long blockNrgLimit = 5000000;
private DataWord blockDifficulty = new DataWord(0x100000000L);
Expand All @@ -69,6 +70,7 @@ public void setup() {
nrgLimit = 20000;
callValue = DataWord.ZERO;
callData = new byte[0];
CfgAion.inst().setForkProperties();
}

@Test
Expand Down

0 comments on commit 0dc8939

Please sign in to comment.