use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AvmBulkTransactionTest method importBlockWithContractDeploysAndSubsequentCalls.
/**
* Ensures that AVM contracts can be deployed and called within the same block.
*/
@Test
public void importBlockWithContractDeploysAndSubsequentCalls() {
BigInteger expectedNonce = getNonce(deployerKey);
BigInteger initialBalance = getBalance(deployerKey);
// note: 3 contract deployments would pass the block energy limit
int nbCreateTransactions = 2;
int nbCallTransactions = 2;
int nbTransactions = nbCreateTransactions + nbCreateTransactions * nbCallTransactions;
List<AionTransaction> transactions = new ArrayList<>();
for (int j = 0; j < nbCreateTransactions; j++) {
// create contract transaction
AionTransaction deployTx = makeAvmContractCreateTransaction(deployerKey, expectedNonce);
expectedNonce = expectedNonce.add(BigInteger.ONE);
AionAddress deployedContract = TxUtil.calculateContractAddress(deployTx);
transactions.add(deployTx);
// subsequent call transactions
for (int i = 0; i < nbCallTransactions; i++) {
transactions.add(makeAvmContractCallTransaction(deployerKey, expectedNonce, deployedContract));
expectedNonce = expectedNonce.add(BigInteger.ONE);
}
}
// process the transactions in bulk
AionBlockSummary blockSummary = sendTransactionsInBulkInSingleBlock(transactions);
// verify all transactions were successful
assertEquals(nbTransactions, blockSummary.getSummaries().size());
for (AionTxExecSummary transactionSummary : blockSummary.getSummaries()) {
System.out.println(transactionSummary.getReceipt());
assertTrue(transactionSummary.getReceipt().isSuccessful());
}
BigInteger expectedBalance = initialBalance;
for (int i = 0; i < nbTransactions; i++) {
BigInteger energyUsed = BigInteger.valueOf(blockSummary.getSummaries().get(i).getReceipt().getEnergyUsed());
expectedBalance = expectedBalance.subtract(energyUsed.multiply(BigInteger.valueOf(energyPrice)));
}
assertEquals(expectedBalance, getBalance(deployerKey));
assertEquals(expectedNonce, getNonce(deployerKey));
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class GenesisSpecificationTest method overrideGenesisBlockTest.
/**
* Test that the genesis block can be overrode by certain configuration options that correspond
* to the options provided by {@link AionGenesis.Builder}
*/
@Test
public void overrideGenesisBlockTest() {
AionGenesis.Builder genesisBuilder = new AionGenesis.Builder();
// values to override defaults with
byte[] overrideHash = ByteUtil.hexStringToBytes("DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF");
byte[] overrideAddress = ByteUtil.hexStringToBytes("DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF");
BigInteger overrideValue = BigInteger.valueOf(1337);
AccountState defaultAccountState = new AccountState(overrideValue, overrideValue);
HashSet<AionAddress> accountStateSet = new HashSet<>();
accountStateSet.add(new AionAddress(overrideHash));
genesisBuilder.withParentHash(overrideHash).withCoinbase(new AionAddress(overrideAddress)).withDifficulty(overrideValue.toByteArray()).withEnergyLimit(overrideValue.longValue()).withNonce(overrideHash).withNumber(overrideValue.longValue()).withTimestamp(overrideValue.longValue()).addPreminedAccount(new AionAddress(overrideAddress), defaultAccountState);
AionGenesis genesis = genesisBuilder.buildForTest();
assertThat(genesis.getParentHash()).isEqualTo(overrideHash);
assertThat(genesis.getCoinbase().toByteArray()).isEqualTo(overrideAddress);
assertThat(genesis.getDifficulty()).isEqualTo(overrideValue.toByteArray());
assertThat(genesis.getDifficultyBI()).isEqualTo(overrideValue);
assertThat(genesis.getTimestamp()).isEqualTo(overrideValue.longValue());
assertThat(genesis.getNrgConsumed()).isEqualTo(0);
assertThat(genesis.getNrgLimit()).isEqualTo(overrideValue.longValue());
assertThat(genesis.getTxTrieRoot()).isEqualTo(ConstantUtil.EMPTY_TRIE_HASH);
assertThat(genesis.getReceiptsRoot()).isEqualTo(ConstantUtil.EMPTY_TRIE_HASH);
assertThat(genesis.getDifficultyBI()).isEqualTo(overrideValue);
assertThat(genesis.getTransactionsList().isEmpty()).isEqualTo(true);
assertThat(genesis.getPremine().keySet()).isEqualTo(accountStateSet);
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class StakingBlockHeaderTest method testBlockHeaderFromRLP.
// Test is a self referencing
@Test
public void testBlockHeaderFromRLP() {
long time = System.currentTimeMillis() / 1000;
StakingBlockHeader.Builder builder = StakingBlockHeader.Builder.newInstance();
builder.fromUnsafeSource().withCoinbase(new AionAddress(COINBASE)).withTxTrieRoot(TRIE_ROOT).withExtraData(EXTRA_DATA).withReceiptTrieRoot(RECEIPT_ROOT).withTimestamp(time).withNumber(NUMBER_BYTES).withEnergyConsumed(ENERGY_CONSUMED_BYTES).withEnergyLimit(ENERGY_LIMIT_BYTES).withParentHash(PARENT_HASH).withSeed(SEED).withSigningPublicKey(SIGNINGPUBKEY).withSignature(SIGNATURE).withDefaultStateRoot().withDefaultLogsBloom().withDefaultDifficulty();
StakingBlockHeader header = builder.build();
byte[] encoded = header.getEncoded();
StakingBlockHeader reconstructed = StakingBlockHeader.Builder.newInstance(true).withRlpEncodedData(encoded).build();
assertThat(reconstructed.getCoinbase()).isEqualTo(header.getCoinbase());
assertThat(reconstructed.getTxTrieRoot()).isEqualTo(header.getTxTrieRoot());
assertThat(reconstructed.getExtraData()).isEqualTo(header.getExtraData());
assertThat(reconstructed.getReceiptsRoot()).isEqualTo(header.getReceiptsRoot());
assertThat(reconstructed.getTimestamp()).isEqualTo(header.getTimestamp());
assertThat(reconstructed.getNumber()).isEqualTo(header.getNumber());
assertThat(reconstructed.getEnergyConsumed()).isEqualTo(header.getEnergyConsumed());
assertThat(reconstructed.getEnergyLimit()).isEqualTo(header.getEnergyLimit());
assertThat(reconstructed.getParentHash()).isEqualTo(header.getParentHash());
assertThat(reconstructed.getSeedOrProof()).isEqualTo(header.getSeedOrProof());
assertThat(reconstructed.getSignature()).isEqualTo(header.getSignature());
assertThat(reconstructed.getSigningPublicKey()).isEqualTo(header.getSigningPublicKey());
assertThat(reconstructed.getStateRoot()).isEqualTo(header.getStateRoot());
assertThat(reconstructed.getDifficulty()).isEqualTo(header.getDifficulty());
assertThat(reconstructed.getSealType() == header.getSealType());
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class StakingBlockHeaderTest method testBlockHeaderFromRLPwithProof.
@Test
public void testBlockHeaderFromRLPwithProof() {
long time = System.currentTimeMillis() / 1000;
StakingBlockHeader.Builder builder = StakingBlockHeader.Builder.newInstance();
builder.fromUnsafeSource().withCoinbase(new AionAddress(COINBASE)).withTxTrieRoot(TRIE_ROOT).withExtraData(EXTRA_DATA).withReceiptTrieRoot(RECEIPT_ROOT).withTimestamp(time).withNumber(NUMBER_BYTES).withEnergyConsumed(ENERGY_CONSUMED_BYTES).withEnergyLimit(ENERGY_LIMIT_BYTES).withParentHash(PARENT_HASH).withProof(StakingBlockHeader.DEFAULT_PROOF).withSigningPublicKey(SIGNINGPUBKEY).withSignature(SIGNATURE).withDefaultStateRoot().withDefaultLogsBloom().withDefaultDifficulty();
StakingBlockHeader header = builder.build();
byte[] encoded = header.getEncoded();
StakingBlockHeader reconstructed = StakingBlockHeader.Builder.newInstance(true).withRlpEncodedData(encoded).build();
assertThat(reconstructed.getCoinbase()).isEqualTo(header.getCoinbase());
assertThat(reconstructed.getTxTrieRoot()).isEqualTo(header.getTxTrieRoot());
assertThat(reconstructed.getExtraData()).isEqualTo(header.getExtraData());
assertThat(reconstructed.getReceiptsRoot()).isEqualTo(header.getReceiptsRoot());
assertThat(reconstructed.getTimestamp()).isEqualTo(header.getTimestamp());
assertThat(reconstructed.getNumber()).isEqualTo(header.getNumber());
assertThat(reconstructed.getEnergyConsumed()).isEqualTo(header.getEnergyConsumed());
assertThat(reconstructed.getEnergyLimit()).isEqualTo(header.getEnergyLimit());
assertThat(reconstructed.getParentHash()).isEqualTo(header.getParentHash());
assertThat(reconstructed.getSeedOrProof()).isEqualTo(header.getSeedOrProof());
assertThat(reconstructed.getSignature()).isEqualTo(header.getSignature());
assertThat(reconstructed.getSigningPublicKey()).isEqualTo(header.getSigningPublicKey());
assertThat(reconstructed.getStateRoot()).isEqualTo(header.getStateRoot());
assertThat(reconstructed.getDifficulty()).isEqualTo(header.getDifficulty());
assertThat(reconstructed.getSealType() == header.getSealType());
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class StakingBlockHeaderTest method testBlockHeaderFromRLPwithInvalidSeedProofLength.
@Test(expected = IllegalArgumentException.class)
public void testBlockHeaderFromRLPwithInvalidSeedProofLength() {
long time = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
byte[] number = RLP.encodeBigInteger(new BigInteger(1, NUMBER_BYTES));
byte[] parentHash = RLP.encodeElement(PARENT_HASH);
byte[] coinbase = RLP.encodeElement(new AionAddress(COINBASE).toByteArray());
byte[] stateRoot = RLP.encodeElement(ConstantUtil.EMPTY_TRIE_HASH);
byte[] txTrieRoot = RLP.encodeElement(TRIE_ROOT);
byte[] receiptTrieRoot = RLP.encodeElement(RECEIPT_ROOT);
byte[] logsBloom = RLP.encodeElement(EMPTY_BLOOM);
byte[] difficulty = RLP.encodeElement(ByteUtil.EMPTY_HALFWORD);
byte[] extraData = RLP.encodeElement(EXTRA_DATA);
byte[] energyConsumed = RLP.encodeBigInteger(new BigInteger(1, ENERGY_CONSUMED_BYTES));
byte[] energyLimit = RLP.encodeBigInteger(new BigInteger(1, ENERGY_LIMIT_BYTES));
byte[] timestamp = RLP.encodeBigInteger(BigInteger.valueOf(time));
byte[] seedOrProof = RLP.encodeElement(new byte[StakingBlockHeader.PROOF_LENGTH + 1]);
byte[] signature = RLP.encodeElement(SIGNATURE);
byte[] signingPublicKey = RLP.encodeElement(SIGNINGPUBKEY);
byte[] sealType = RLP.encodeElement(new byte[] { Seal.PROOF_OF_STAKE.getSealId() });
byte[] rlpEncoded = RLP.encodeList(sealType, number, parentHash, coinbase, stateRoot, txTrieRoot, receiptTrieRoot, logsBloom, difficulty, extraData, energyConsumed, energyLimit, timestamp, seedOrProof, signature, signingPublicKey);
StakingBlockHeader reconstructed = StakingBlockHeader.Builder.newInstance(true).withRlpEncodedData(rlpEncoded).build();
}
Aggregations