Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarev committed Nov 17, 2023
1 parent 22f1649 commit 5217aa0
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void getActionFromInvokeData() {
gas,
callValue,
data,
null, null, null, null, null, null,
null, null, null, null, null, null, null,
null, null, 0, null, false, false);

TraceAction action = TraceTransformer.toAction(TraceType.CALL, invoke, CallType.CALL, null, null, null);
Expand Down Expand Up @@ -76,7 +76,7 @@ void getActionFromInvokeDataWithCreationData() {
gas,
callValue,
null,
null, null, null, null, null, null,
null, null, null, null, null, null, null,
null, null, 0, null, false, false);

TraceAction action = TraceTransformer.toAction(TraceType.CREATE, invoke, CallType.NONE, data, null, null);
Expand Down Expand Up @@ -110,7 +110,7 @@ void getActionFromInvokeDataWithCreationDataUsingCreationMethod() {
gas,
callValue,
null,
null, null, null, null, null, null,
null, null, null, null, null, null, null,
null, null, 0, null, false, false);

TraceAction action = TraceTransformer.toAction(TraceType.CREATE, invoke, CallType.NONE, data, "create2", null);
Expand Down
17 changes: 14 additions & 3 deletions rskj-core/src/test/java/org/ethereum/jsontestsuite/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ public class Env {
private final byte[] currentCoinbase;
private final byte[] currentDifficulty;
private final byte[] currentGasLimit;
private final byte[] currentMinimumGasPrice;
private final byte[] currentNumber;
private final byte[] currentTimestamp;
private final byte[] previousHash;


public Env(byte[] currentCoinbase, byte[] currentDifficulty, byte[]
currentGasLimit, byte[] currentNumber, byte[]
currentTimestamp, byte[] previousHash) {
currentGasLimit, byte[] currentMinimumGasPrice,
byte[] currentNumber, byte[] currentTimestamp,
byte[] previousHash) {
this.currentCoinbase = currentCoinbase;
this.currentDifficulty = currentDifficulty;
this.currentGasLimit = currentGasLimit;
this.currentMinimumGasPrice = currentMinimumGasPrice;
this.currentNumber = currentNumber;
this.currentTimestamp = currentTimestamp;
this.previousHash = previousHash;
Expand All @@ -54,6 +57,7 @@ public Env(byte[] currentCoinbase, byte[] currentDifficulty, byte[]
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentMinimumGasPrice" : "777",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
Expand All @@ -65,12 +69,14 @@ public Env(JsonNode env) {
String timestamp = env.get("currentTimestamp").asText();
String number = env.get("currentNumber").asText();
String gasLimit = org.ethereum.json.Utils.parseUnidentifiedBase(env.get("currentGasLimit").asText());
String minimumGasPrice = org.ethereum.json.Utils.parseUnidentifiedBase(env.get("minimumGasPrice").asText());
JsonNode previousHash = env.get("previousHash");
String prevHash = previousHash == null ? "" : previousHash.asText();

this.currentCoinbase = Hex.decode(coinbase);
this.currentDifficulty = BigIntegers.asUnsignedByteArray(TestingCase.toBigInt(difficulty) );
this.currentGasLimit = BigIntegers.asUnsignedByteArray(TestingCase.toBigInt(gasLimit));
this.currentGasLimit = BigIntegers.asUnsignedByteArray(TestingCase.toBigInt(gasLimit));
this.currentMinimumGasPrice = BigIntegers.asUnsignedByteArray(TestingCase.toBigInt(minimumGasPrice));
this.currentNumber = TestingCase.toBigInt(number).toByteArray();
this.currentTimestamp = TestingCase.toBigInt(timestamp).toByteArray();
this.previousHash = Hex.decode(prevHash);
Expand All @@ -89,6 +95,10 @@ public byte[] getCurrentGasLimit() {
return currentGasLimit;
}

public byte[] getCurrentMinimumGasPrice() {
return currentMinimumGasPrice;
}

public byte[] getCurrentNumber() {
return currentNumber;
}
Expand All @@ -107,6 +117,7 @@ public String toString() {
"currentCoinbase=" + ByteUtil.toHexString(currentCoinbase) +
", currentDifficulty=" + ByteUtil.toHexString(currentDifficulty) +
", currentGasLimit=" + ByteUtil.toHexString(currentGasLimit) +
", currentMinimumGasPrice=" + ByteUtil.toHexString(currentMinimumGasPrice) +
", currentNumber=" + ByteUtil.toHexString(currentNumber) +
", currentTimestamp=" + ByteUtil.toHexString(currentTimestamp) +
", previousHash=" + ByteUtil.toHexString(previousHash) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public TestProgramInvokeFactory(Env env) {

@Override
public ProgramInvoke createProgramInvoke(Transaction tx, int txindex, Block block, Repository repository, BlockStore blockStore, SignatureCache signatureCache) {
return generalInvoke(tx, txindex, repository, blockStore, signatureCache);
return generalInvoke(tx, txindex, block, repository, blockStore, signatureCache);
}

@Override
Expand All @@ -59,7 +59,7 @@ public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, Da
return null;
}

private ProgramInvoke generalInvoke(Transaction tx, int txindex, Repository repository, BlockStore blockStore, SignatureCache signatureCache) {
private ProgramInvoke generalInvoke(Transaction tx, int txindex, Block block, Repository repository, BlockStore blockStore, SignatureCache signatureCache) {

/*** ADDRESS op ***/
// YP: Get address of currently executing account.
Expand All @@ -77,7 +77,7 @@ private ProgramInvoke generalInvoke(Transaction tx, int txindex, Repository repo
Coin balance = repository.getBalance(addr);

/*** GASPRICE op ***/
Coin gasPrice = tx.getGasPrice();
Coin txGasPrice = tx.getGasPrice();

/*** GAS op ***/
byte[] gas = tx.getGasLimit();
Expand Down Expand Up @@ -109,9 +109,12 @@ private ProgramInvoke generalInvoke(Transaction tx, int txindex, Repository repo
/*** GASLIMIT op ***/
byte[] gaslimit = env.getCurrentGasLimit();

/*** BASEFEE op ***/
Coin minimumGasPrice = block.getMinimumGasPrice();

return new ProgramInvokeImpl(addr.getBytes(), origin.getBytes(), caller.getBytes(), balance.getBytes(),
gasPrice.getBytes(), gas, callValue.getBytes(), data, lastHash, coinbase,
timestamp, number, txindex, difficulty, gaslimit, repository, blockStore);
txGasPrice.getBytes(), gas, callValue.getBytes(), data, lastHash, coinbase,
timestamp, number, txindex, difficulty, gaslimit, minimumGasPrice.getBytes(), repository, blockStore);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public List<String> runTestCase(TestingCase testCase) {
byte[] origin = exec.getOrigin();
byte[] caller = exec.getCaller();
byte[] balance = ByteUtil.bigIntegerToBytes(repository.getBalance(new RskAddress(exec.getAddress())).asBigInteger());
byte[] gasPrice = exec.getGasPrice();
byte[] txGasPrice = exec.getGasPrice();
byte[] gas = exec.getGas();
byte[] callValue = exec.getValue();
byte[] msgData = exec.getData();
Expand All @@ -262,6 +262,7 @@ public List<String> runTestCase(TestingCase testCase) {
long number = ByteUtil.byteArrayToLong(env.getCurrentNumber());
byte[] difficulty = env.getCurrentDifficulty();
byte[] gaslimit = env.getCurrentGasLimit();
byte[] minimumGasPrice = env.getCurrentMinimumGasPrice();

// Origin and caller need to exist in order to be able to execute
RskAddress originAddress = new RskAddress(origin);
Expand All @@ -274,8 +275,8 @@ public List<String> runTestCase(TestingCase testCase) {
}

ProgramInvoke programInvoke = new ProgramInvokeImpl(address, origin, caller, balance,
gasPrice, gas, callValue, msgData, lastHash, coinbase,
timestamp, number, 0, difficulty, gaslimit, repository, new BlockStoreDummy(), true);
txGasPrice, gas, callValue, msgData, lastHash, coinbase,
timestamp, number, 0, difficulty, gaslimit, minimumGasPrice, repository, new BlockStoreDummy(), true);

/* 3. Create Program - exec.code */
/* 4. run VM */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public static Env build(EnvTck envTck){
byte[] coinbase = parseData(envTck.getCurrentCoinbase());
byte[] difficulty = parseVarData(envTck.getCurrentDifficulty());
byte[] gasLimit = parseVarData(envTck.getCurrentGasLimit());
byte[] minimumGasPrice = parseVarData(envTck.getCurrentMinimumGasPrice());
byte[] number = parseNumericData(envTck.getCurrentNumber());
byte[] timestamp = parseNumericData(envTck.getCurrentTimestamp());
byte[] hash = parseData(envTck.getPreviousHash());

return new Env(coinbase, difficulty, gasLimit, number, timestamp, hash);
return new Env(coinbase, difficulty, gasLimit, minimumGasPrice, number, timestamp, hash);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class EnvTck {
String currentCoinbase;
String currentDifficulty;
String currentGasLimit;
String currentMinimumGasPrice;
String currentNumber;
String currentTimestamp;
String previousHash;
Expand Down Expand Up @@ -55,6 +56,14 @@ public void setCurrentGasLimit(String currentGasLimit) {
this.currentGasLimit = currentGasLimit;
}

public String getCurrentMinimumGasPrice() {
return currentMinimumGasPrice;
}

public void setCurrentMinimumGasPrice(String currentMinimumGasPrice) {
this.currentMinimumGasPrice = currentMinimumGasPrice;
}

public String getCurrentNumber() {
return currentNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void testEquals_OK() {
int transactionIndex1 = 3;
byte[] difficulty1 = new byte[]{11};
byte[] gasLimit1 = new byte[]{12};
byte[] minimumGasPrice1 = new byte[]{13};
Repository repository1 = RepositoryBuilder.build(Collections.emptyMap());
BlockStore blockStore1 = new BlockStoreDummy();
boolean byTestingSuite1 = true;
Expand All @@ -51,13 +52,14 @@ void testEquals_OK() {
int transactionIndex2 = 2;
byte[] difficulty2 = new byte[]{2};
byte[] gasLimit2 = new byte[]{1};
byte[] minimumGasPrice2 = new byte[]{14};
Repository repository2 = null;
BlockStore blockStore2 = null;
boolean byTestingSuite2 = false;

// An object must be equal to itself

ProgramInvokeImpl programInvokeA = new ProgramInvokeImpl(address1, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, repository1, blockStore1, byTestingSuite1);
ProgramInvokeImpl programInvokeA = new ProgramInvokeImpl(address1, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, minimumGasPrice1, repository1, blockStore1, byTestingSuite1);

assertEquals(programInvokeA, programInvokeA);

Expand All @@ -67,15 +69,15 @@ void testEquals_OK() {

// Same property values make objects to be equal

ProgramInvokeImpl programInvokeB = new ProgramInvokeImpl(address1, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, repository1, blockStore1, byTestingSuite1);
ProgramInvokeImpl programInvokeB = new ProgramInvokeImpl(address1, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, minimumGasPrice1, repository1, blockStore1, byTestingSuite1);

assertEquals(programInvokeA, programInvokeB);

// Different combinations of property values make objects to be different

ProgramInvokeImpl programInvokeC = new ProgramInvokeImpl(address2, origin2, caller2, balance2, gasPrice2, gas2, callValue2, msgData2, lastHash2, coinbase2, timestamp2, number2, transactionIndex2, difficulty2, gasLimit2, repository2, blockStore2, byTestingSuite2);
ProgramInvokeImpl programInvokeD = new ProgramInvokeImpl(address2, origin2, caller2, balance1, gasPrice2, gas2, callValue2, msgData2, lastHash2, coinbase2, timestamp2, number1, transactionIndex2, difficulty2, gasLimit2, repository2, blockStore2, byTestingSuite2);
ProgramInvokeImpl programInvokeE = new ProgramInvokeImpl(address2, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, repository1, blockStore1, byTestingSuite1);
ProgramInvokeImpl programInvokeC = new ProgramInvokeImpl(address2, origin2, caller2, balance2, gasPrice2, gas2, callValue2, msgData2, lastHash2, coinbase2, timestamp2, number2, transactionIndex2, difficulty2, gasLimit2, minimumGasPrice2, repository2, blockStore2, byTestingSuite2);
ProgramInvokeImpl programInvokeD = new ProgramInvokeImpl(address2, origin2, caller2, balance1, gasPrice2, gas2, callValue2, msgData2, lastHash2, coinbase2, timestamp2, number1, transactionIndex2, difficulty2, gasLimit2, minimumGasPrice2, repository2, blockStore2, byTestingSuite2);
ProgramInvokeImpl programInvokeE = new ProgramInvokeImpl(address2, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, minimumGasPrice1, repository1, blockStore1, byTestingSuite1);

assertNotEquals(programInvokeA, programInvokeC);
assertNotEquals(programInvokeA, programInvokeD);
Expand Down Expand Up @@ -103,6 +105,7 @@ void testHashcode_OK() {
int transactionIndex1 = 3;
byte[] difficulty1 = new byte[]{11};
byte[] gasLimit1 = new byte[]{12};
byte[] minimumGasPrice1 = new byte[]{13};
Repository repository1 = RepositoryBuilder.build(Collections.emptyMap());
BlockStore blockStore1 = new BlockStoreDummy();
boolean byTestingSuite1 = true;
Expand All @@ -122,20 +125,21 @@ void testHashcode_OK() {
int transactionIndex2 = 2;
byte[] difficulty2 = new byte[]{2};
byte[] gasLimit2 = new byte[]{1};
byte[] minimumGasPrice2 = new byte[]{14};
Repository repository2 = null;
BlockStore blockStore2 = null;
boolean byTestingSuite2 = false;

// Same properties included in the hashcode makes hashcode to be equal

ProgramInvokeImpl programInvokeA = new ProgramInvokeImpl(address1, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, repository1, blockStore1, byTestingSuite1);
ProgramInvokeImpl programInvokeB = new ProgramInvokeImpl(address1, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, repository1, blockStore1, byTestingSuite1);
ProgramInvokeImpl programInvokeA = new ProgramInvokeImpl(address1, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, minimumGasPrice1, repository1, blockStore1, byTestingSuite1);
ProgramInvokeImpl programInvokeB = new ProgramInvokeImpl(address1, origin1, caller1, balance1, gasPrice1, gas1, callValue1, msgData1, lastHash1, coinbase1, timestamp1, number1, transactionIndex1, difficulty1, gasLimit1, minimumGasPrice1, repository1, blockStore1, byTestingSuite1);

assertEquals(programInvokeA.hashCode(), programInvokeB.hashCode());

// Different combinations of property values makes hashcode to be different

ProgramInvokeImpl programInvokeC = new ProgramInvokeImpl(address2, origin2, caller2, balance2, gasPrice2, gas2, callValue2, msgData2, lastHash2, coinbase2, timestamp2, number2, transactionIndex2, difficulty2, gasLimit2, repository2, blockStore2, byTestingSuite2);
ProgramInvokeImpl programInvokeC = new ProgramInvokeImpl(address2, origin2, caller2, balance2, gasPrice2, gas2, callValue2, msgData2, lastHash2, coinbase2, timestamp2, number2, transactionIndex2, difficulty2, gasLimit2, minimumGasPrice2, repository2, blockStore2, byTestingSuite2);

assertNotEquals(programInvokeA.hashCode(), programInvokeC.hashCode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ public long getGas() {
return gasLimit;
}

/* BASEFEE op */
@Override
public DataWord getMinimumGasPrice() {
byte[] minimumGasPrice = Hex.decode("03104e60a000");
return DataWord.valueOf(minimumGasPrice);
}

public void setGas(long gasLimit) {
this.gasLimit = gasLimit;
}
Expand Down

0 comments on commit 5217aa0

Please sign in to comment.