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));
}
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);
}
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();
}
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);
}
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);
}
Aggregations