Search in sources :

Example 16 with Address

use of org.aion.base.type.Address 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)

Example 17 with Address

use of org.aion.base.type.Address in project aion by aionnetwork.

the class PendingTxCacheTest method flushTest1.

@Test
public void flushTest1() {
    PendingTxCache cache = new PendingTxCache(1);
    List<AionTransaction> txn = getMockTransaction(0, 10, 0);
    List<AionTransaction> newCache = new ArrayList<>();
    for (ITransaction tx : txn) {
        newCache.add(cache.addCacheTx((AionTransaction) tx).get(0));
    }
    assertTrue(newCache.size() == 10);
    Map<Address, BigInteger> map = new HashMap<>();
    map.put(Address.wrap(key.get(0).getAddress()), BigInteger.TWO);
    newCache = cache.flush(map);
    assertTrue(newCache.size() == 1);
    Map<BigInteger, AionTransaction> cacheMap = cache.geCacheTx(Address.wrap(key.get(0).getAddress()));
    assertTrue(cacheMap.size() == 8);
}
Also used : Address(org.aion.base.type.Address) HashMap(java.util.HashMap) ITransaction(org.aion.base.type.ITransaction) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 18 with Address

use of org.aion.base.type.Address in project aion by aionnetwork.

the class BloomFilterTest method testCompositeBloomFiltering.

@Test
public void testCompositeBloomFiltering() {
    Address addr = new Address("BEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEFFFF");
    byte[] someEvent = HashUtil.h256(BigInteger.ONE.toByteArray());
    byte[] anotherEvent = HashUtil.h256(BigInteger.TWO.toByteArray());
    Bloom bloom = BloomFilter.create(addr.toBytes(), someEvent, anotherEvent);
    assertThat(BloomFilter.containsAddress(bloom, addr)).isTrue();
    assertThat(BloomFilter.containsEvent(bloom, someEvent)).isTrue();
    // test filtering composite
    Bloom compositeTargetBloom = BloomFilter.create(someEvent, anotherEvent);
    assertThat(BloomFilter.contains(bloom, compositeTargetBloom)).isTrue();
}
Also used : Address(org.aion.base.type.Address) Bloom(org.aion.mcf.vm.types.Bloom) Test(org.junit.Test)

Example 19 with Address

use of org.aion.base.type.Address in project aion by aionnetwork.

the class AionRepositoryImplTest method test17NodePreviousRootTest.

// test that intermediate nodes also get rolled back properly
// intermediate nodes get created when two accounts have a common substring
@Test
public void test17NodePreviousRootTest() {
    // not that it matters since things are going to be hashed, but at least
    // the root node should point to a node that contains references to both
    final Address DOG_ACC = Address.wrap("00000000000000000000000000000dog".getBytes());
    final Address DOGE_ACC = Address.wrap("0000000000000000000000000000doge".getBytes());
    AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    IRepositoryCache track = repository.startTracking();
    track.addBalance(DOG_ACC, BigInteger.ONE);
    track.addBalance(DOGE_ACC, BigInteger.ONE);
    track.flush();
    final byte[] root = repository.getRoot();
    repository.flush();
    System.out.println("trie state after adding two accounts");
    System.out.println(repository.getWorldState().getTrieDump());
    track = repository.startTracking();
    track.addBalance(DOG_ACC, BigInteger.ONE);
    track.flush();
    System.out.println("trie state after updating balance on one account");
    System.out.println(repository.getWorldState().getTrieDump());
    assertThat(repository.getBalance(DOG_ACC)).isEqualTo(BigInteger.TWO);
    repository.flush();
    repository.syncToRoot(root);
    assertThat(repository.getBalance(DOG_ACC)).isEqualTo(BigInteger.ONE);
}
Also used : Address(org.aion.base.type.Address) IRepositoryCache(org.aion.base.db.IRepositoryCache) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) Test(org.junit.Test)

Example 20 with Address

use of org.aion.base.type.Address in project aion by aionnetwork.

the class AionRepositoryImplTest method testSyncToPreviousRootWithFlush.

@Test
public void testSyncToPreviousRootWithFlush() {
    final Address FIRST_ACC = Address.wrap("CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE");
    AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
    byte[] originalRoot = repository.getRoot();
    IRepositoryCache track = repository.startTracking();
    track.addBalance(FIRST_ACC, BigInteger.ONE);
    track.flush();
    byte[] newRoot = repository.getRoot();
    System.out.println("state after add one account");
    System.out.println(repository.getWorldState().getTrieDump());
    // flush into cache/db
    repository.flush();
    track = repository.startTracking();
    // total should be 2
    track.addBalance(FIRST_ACC, BigInteger.ONE);
    track.flush();
    assertThat(repository.getBalance(FIRST_ACC)).isEqualTo(BigInteger.TWO);
    System.out.println("state after adding balance to FIRST_ACC");
    System.out.println(repository.getWorldState().getTrieDump());
    // flush this state into cache/db
    repository.flush();
    repository.setRoot(newRoot);
    System.out.println("state after rewinding to previous root");
    System.out.println(repository.getWorldState().getTrieDump());
    assertThat(repository.getBalance(FIRST_ACC)).isEqualTo(BigInteger.ONE);
}
Also used : Address(org.aion.base.type.Address) IRepositoryCache(org.aion.base.db.IRepositoryCache) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) Test(org.junit.Test)

Aggregations

Address (org.aion.base.type.Address)61 Test (org.junit.Test)34 BigInteger (java.math.BigInteger)29 AionTransaction (org.aion.zero.types.AionTransaction)23 ITransaction (org.aion.base.type.ITransaction)14 ECKey (org.aion.crypto.ECKey)13 DataWord (org.aion.mcf.vm.types.DataWord)11 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)10 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)9 IRepositoryCache (org.aion.base.db.IRepositoryCache)8 HashMap (java.util.HashMap)6 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)5 ByteUtil.toHexString (org.aion.base.util.ByteUtil.toHexString)5 AccountState (org.aion.mcf.core.AccountState)5 AionBlock (org.aion.zero.impl.types.AionBlock)5 ArrayList (java.util.ArrayList)4 ImportResult (org.aion.mcf.core.ImportResult)4 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)3 IRepository (org.aion.base.db.IRepository)3 AionContractDetailsImpl (org.aion.zero.db.AionContractDetailsImpl)3