use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class AionRepositoryCacheTest method testGetStorageValueWithDoubleZeroKey.
@Test
public void testGetStorageValueWithDoubleZeroKey() {
AionAddress address = getNewAddress();
ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
cache.addStorageRow(address, ZERO_WRAPPED_32, value);
assertEquals(value, cache.getStorageValue(address, ZERO_WRAPPED_32));
value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
cache.addStorageRow(address, ZERO_WRAPPED_32, value);
assertEquals(value, cache.getStorageValue(address, ZERO_WRAPPED_32));
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class AionTransactionTest method testTransactionCost2.
@Test
public void testTransactionCost2() {
byte[] nonce = BigInteger.ONE.toByteArray();
byte[] value = BigInteger.ONE.toByteArray();
byte[] data = RandomUtils.nextBytes(128);
long nrg = new DataWord(1000L).longValue();
long nrgPrice = DataWord.ONE.longValue();
AionTransaction tx = AionTransaction.create(key, nonce, null, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
long expected = 200000 + 21000;
for (byte b : data) {
expected += (b == 0) ? 4 : 64;
}
assertEquals(expected, TxUtil.calculateTransactionCost(tx));
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class AionTransactionTest method testTransactionCost.
@Test
public void testTransactionCost() {
byte[] nonce = BigInteger.ONE.toByteArray();
byte[] to = RandomUtils.nextBytes(AionAddress.LENGTH);
byte[] value = BigInteger.ONE.toByteArray();
byte[] data = RandomUtils.nextBytes(128);
long nrg = new DataWord(1000L).longValue();
long nrgPrice = DataWord.ONE.longValue();
AionTransaction tx = AionTransaction.create(key, nonce, new AionAddress(to), value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
long expected = 21000;
for (byte b : data) {
expected += (b == 0) ? 4 : 64;
}
assertEquals(expected, TxUtil.calculateTransactionCost(tx));
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class TokenBridgeContractTest method testMemberCount.
@Test
public void testMemberCount() {
// override defaults
this.contract = new TokenBridgeContract(context(OWNER_ADDR, CONTRACT_ADDR), ExternalStateForTests.usingRepository(this.repository), OWNER_ADDR, CONTRACT_ADDR);
this.connector = this.contract.getConnector();
ListFVM encodingList = new ListFVM();
for (ECKey k : members) {
encodingList.add(new AddressFVM(k.getAddress()));
}
byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
assertTrue(result.getStatus().isSuccess());
// try before
byte[] callPayload = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
assertTrue(transferResult.getStatus().isSuccess());
assertThat(transferResult.getReturnData()).isEqualTo(new DataWord(new BigInteger("5")).getData());
// explicitly set the member count to 10
this.connector.setMemberCount(10);
// try after
byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG);
assertTrue(transferResult2.getStatus().isSuccess());
assertThat(transferResult2.getReturnData()).isEqualTo(new DataWord(new BigInteger("10")).getData());
}
Aggregations