use of org.aion.zero.impl.db.AionRepositoryCache in project aion by aionnetwork.
the class ContractIntegTest method testRedeployContractAtExistentContractAddress.
@Test
public void testRedeployContractAtExistentContractAddress() throws Exception {
String contractName = "MultiFeatureContract";
byte[] deployCode = getDeployCode(contractName);
long nrg = 1_000_000;
long nrgPrice = energyPrice;
BigInteger value = BigInteger.ZERO;
BigInteger nonce = BigInteger.ZERO;
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
// Mock up the repo so that the contract address already exists.
AionRepositoryCache repo = mock(AionRepositoryCache.class);
when(repo.hasAccountState(Mockito.any(AionAddress.class))).thenReturn(true);
when(repo.getNonce(Mockito.any(AionAddress.class))).thenReturn(nonce);
when(repo.getBalance(Mockito.any(AionAddress.class))).thenReturn(Builder.DEFAULT_BALANCE);
when(repo.getCode(Mockito.any(AionAddress.class))).thenReturn(new byte[1]);
when(repo.startTracking()).thenReturn(repo);
assertTrue(tx.isContractCreationTransaction());
assertEquals(Builder.DEFAULT_BALANCE, blockchain.getRepository().getBalance(deployer));
assertEquals(BigInteger.ZERO, blockchain.getRepository().getNonce(deployer));
MiningBlock block = makeBlock(tx);
AionTxExecSummary summary = executeTransaction(tx, block, repo);
if (txType == TransactionTypes.DEFAULT) {
assertEquals("FAILURE", summary.getReceipt().getError());
assertEquals(nrg, summary.getNrgUsed().longValue());
} else if (txType == TransactionTypes.AVM_CREATE_CODE) {
assertEquals("Failed: invalid data", summary.getReceipt().getError());
assertEquals(nrg, summary.getNrgUsed().longValue());
}
}
use of org.aion.zero.impl.db.AionRepositoryCache in project aion by aionnetwork.
the class TokenBridgeContractTest method before.
@Before
public void before() {
RepositoryConfig repoConfig = new RepositoryConfig() {
@Override
public String getDbPath() {
return "";
}
@Override
public PruneConfig getPruneConfig() {
return new CfgPrune(false);
}
@Override
public Properties getDatabaseConfig(String db_name) {
Properties props = new Properties();
props.setProperty(DatabaseFactory.Props.DB_TYPE, DBVendor.MOCKDB.toValue());
return props;
}
};
this.repository = new AionRepositoryCache(AionRepositoryImpl.createForTesting(repoConfig));
// override defaults
this.contract = new TokenBridgeContract(dummyContext(), ExternalStateForTests.usingRepository(this.repository), OWNER_ADDR, CONTRACT_ADDR);
this.connector = this.contract.getConnector();
}
use of org.aion.zero.impl.db.AionRepositoryCache in project aion by aionnetwork.
the class ExternalStateForTests method usingDefaultRepository.
public static ExternalStateForTests usingDefaultRepository() {
RepositoryConfig repoConfig = new RepositoryConfig() {
@Override
public String getDbPath() {
return "";
}
@Override
public PruneConfig getPruneConfig() {
return new CfgPrune(false);
}
@Override
public Properties getDatabaseConfig(String db_name) {
Properties props = new Properties();
props.setProperty(DatabaseFactory.Props.DB_TYPE, DBVendor.MOCKDB.toValue());
return props;
}
};
AionRepositoryCache repository = new AionRepositoryCache(AionRepositoryImpl.createForTesting(repoConfig));
return new ExternalStateForTests(repository);
}
Aggregations