Search in sources :

Example 1 with AionRepositoryCache

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());
    }
}
Also used : AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) AionRepositoryCache(org.aion.zero.impl.db.AionRepositoryCache) Test(org.junit.Test)

Example 2 with AionRepositoryCache

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();
}
Also used : RepositoryConfig(org.aion.zero.impl.db.RepositoryConfig) TokenBridgeContract(org.aion.precompiled.contracts.ATB.TokenBridgeContract) CfgPrune(org.aion.zero.impl.config.CfgPrune) Properties(java.util.Properties) AionRepositoryCache(org.aion.zero.impl.db.AionRepositoryCache) Before(org.junit.Before)

Example 3 with AionRepositoryCache

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);
}
Also used : RepositoryConfig(org.aion.zero.impl.db.RepositoryConfig) CfgPrune(org.aion.zero.impl.config.CfgPrune) Properties(java.util.Properties) AionRepositoryCache(org.aion.zero.impl.db.AionRepositoryCache)

Aggregations

AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)3 Properties (java.util.Properties)2 CfgPrune (org.aion.zero.impl.config.CfgPrune)2 RepositoryConfig (org.aion.zero.impl.db.RepositoryConfig)2 BigInteger (java.math.BigInteger)1 AionTransaction (org.aion.base.AionTransaction)1 AionTxExecSummary (org.aion.base.AionTxExecSummary)1 TokenBridgeContract (org.aion.precompiled.contracts.ATB.TokenBridgeContract)1 AionAddress (org.aion.types.AionAddress)1 MiningBlock (org.aion.zero.impl.types.MiningBlock)1 Before (org.junit.Before)1 Test (org.junit.Test)1