Search in sources :

Example 1 with AionGenesis

use of org.aion.zero.impl.AionGenesis in project aion by aionnetwork.

the class GenesisSpecificationTest method defaultGenesisBlockTest.

/**
 * Test that the default genesis block built from the builder produces the
 * correct genesis specs
 */
@Test
public void defaultGenesisBlockTest() {
    AionGenesis.Builder genesisBuilder = new AionGenesis.Builder();
    AionGenesis genesis = genesisBuilder.build();
    assertThat(genesis.getParentHash()).isEqualTo(AionGenesis.GENESIS_PARENT_HASH);
    assertThat(genesis.getCoinbase()).isEqualTo(AionGenesis.GENESIS_COINBASE);
    assertThat(genesis.getDifficulty()).isEqualTo(AionGenesis.GENESIS_DIFFICULTY);
    assertThat(genesis.getDifficultyBI()).isEqualTo(new BigInteger(1, AionGenesis.GENESIS_DIFFICULTY));
    assertThat(genesis.getLogBloom()).isEqualTo(AionGenesis.GENESIS_LOGSBLOOM);
    assertThat(genesis.getTimestamp()).isEqualTo(AionGenesis.GENESIS_TIMESTAMP);
    assertThat(genesis.getNrgConsumed()).isEqualTo(0);
    assertThat(genesis.getNrgLimit()).isEqualTo(AionGenesis.GENESIS_ENERGY_LIMIT);
    assertThat(genesis.getTxTrieRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
    assertThat(genesis.getReceiptsRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
    assertThat(genesis.getCumulativeDifficulty()).isEqualTo(new BigInteger(1, AionGenesis.GENESIS_DIFFICULTY));
    assertThat(genesis.getTransactionsList().isEmpty()).isEqualTo(true);
    Map<Address, AccountState> premined = genesis.getPremine();
    Set<Address> keySet = premined.keySet();
    // default set
    Set<Address> defaultKeySet = AionGenesis.GENESIS_PREMINE.keySet();
    assertThat(defaultKeySet.equals(keySet)).isEqualTo(true);
}
Also used : Address(org.aion.base.type.Address) BigInteger(java.math.BigInteger) AccountState(org.aion.mcf.core.AccountState) AionGenesis(org.aion.zero.impl.AionGenesis) Test(org.junit.Test)

Example 2 with AionGenesis

use of org.aion.zero.impl.AionGenesis 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<Address> accountStateSet = new HashSet<>();
    accountStateSet.add(Address.wrap(overrideHash));
    genesisBuilder.withParentHash(overrideHash).withCoinbase(Address.wrap(overrideAddress)).withDifficulty(overrideValue.toByteArray()).withEnergyLimit(overrideValue.longValue()).withExtraData(overrideHash).withNonce(overrideHash).withNumber(overrideValue.longValue()).withTimestamp(overrideValue.longValue()).addPreminedAccount(Address.wrap(overrideAddress), defaultAccountState);
    AionGenesis genesis = genesisBuilder.build();
    assertThat(genesis.getParentHash()).isEqualTo(overrideHash);
    assertThat(genesis.getCoinbase().toBytes()).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(HashUtil.EMPTY_TRIE_HASH);
    assertThat(genesis.getReceiptsRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
    assertThat(genesis.getCumulativeDifficulty()).isEqualTo(overrideValue);
    assertThat(genesis.getTransactionsList().isEmpty()).isEqualTo(true);
    assertThat(genesis.getPremine().keySet().equals(accountStateSet));
}
Also used : Address(org.aion.base.type.Address) BigInteger(java.math.BigInteger) AccountState(org.aion.mcf.core.AccountState) AionGenesis(org.aion.zero.impl.AionGenesis) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)2 Address (org.aion.base.type.Address)2 AccountState (org.aion.mcf.core.AccountState)2 AionGenesis (org.aion.zero.impl.AionGenesis)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1