Search in sources :

Example 1 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class AccountBuilder method build.

public static StateWrap build(AccountTck account) {
    ContractDetailsImpl details = new ContractDetailsImpl(new RskSystemProperties());
    details.setCode(parseData(account.getCode()));
    details.setStorage(convertStorage(account.getStorage()));
    AccountState state = new AccountState();
    state.addToBalance(new Coin(unifiedNumericToBigInteger(account.getBalance())));
    state.setNonce(unifiedNumericToBigInteger(account.getNonce()));
    state.setStateRoot(details.getStorageHash());
    state.setCodeHash(HashUtil.keccak256(details.getCode()));
    return new StateWrap(state, details);
}
Also used : Coin(co.rsk.core.Coin) ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) AccountState(org.ethereum.core.AccountState) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 2 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class AccountValidator method valid.

public static List<String> valid(RskAddress addr, AccountState expectedState, ContractDetails expectedDetails, AccountState currentState, ContractDetails currentDetails) {
    List<String> results = new ArrayList<>();
    if (currentState == null || currentDetails == null) {
        String formattedString = String.format("Account: %s: expected but doesn't exist", addr);
        results.add(formattedString);
        return results;
    }
    if (expectedState == null || expectedDetails == null) {
        String formattedString = String.format("Account: %s: unexpected account in the repository", addr);
        results.add(formattedString);
        return results;
    }
    Coin expectedBalance = expectedState.getBalance();
    if (!currentState.getBalance().equals(expectedBalance)) {
        String formattedString = String.format("Account: %s: has unexpected balance, expected balance: %s found balance: %s", addr, expectedBalance.toString(), currentState.getBalance().toString());
        results.add(formattedString);
    }
    BigInteger expectedNonce = expectedState.getNonce();
    if (currentState.getNonce().compareTo(expectedNonce) != 0) {
        String formattedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s", addr, expectedNonce.toString(), currentState.getNonce().toString());
        results.add(formattedString);
    }
    byte[] code = Arrays.equals(currentState.getCodeHash(), EMPTY_DATA_HASH) ? new byte[0] : currentDetails.getCode();
    if (!Arrays.equals(expectedDetails.getCode(), code)) {
        String formattedString = String.format("Account: %s: has unexpected code, expected code: %s found code: %s", addr, Hex.toHexString(expectedDetails.getCode()), Hex.toHexString(currentDetails.getCode()));
        results.add(formattedString);
    }
    // compare storage
    Set<DataWord> currentKeys = currentDetails.getStorage().keySet();
    Set<DataWord> expectedKeys = expectedDetails.getStorage().keySet();
    Set<DataWord> checked = new HashSet<>();
    for (DataWord key : currentKeys) {
        DataWord currentValue = currentDetails.getStorage().get(key);
        DataWord expectedValue = expectedDetails.getStorage().get(key);
        if (expectedValue == null) {
            String formattedString = String.format("Account: %s: has unexpected storage data: %s = %s", addr, key, currentValue);
            results.add(formattedString);
            continue;
        }
        if (!expectedValue.equals(currentValue)) {
            String formattedString = String.format("Account: %s: has unexpected value, for key: %s , expectedValue: %s real value: %s", addr, key.toString(), expectedValue.toString(), currentValue.toString());
            results.add(formattedString);
            continue;
        }
        checked.add(key);
    }
    for (DataWord key : expectedKeys) {
        if (!checked.contains(key)) {
            String formattedString = String.format("Account: %s: doesn't exist expected storage key: %s", addr, key.toString());
            results.add(formattedString);
        }
    }
    return results;
}
Also used : Coin(co.rsk.core.Coin) BigInteger(java.math.BigInteger) DataWord(org.ethereum.vm.DataWord)

Example 3 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class TransactionPoolImplTest method rejectTransactionPoolTransaction.

@Test
public void rejectTransactionPoolTransaction() {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx = createSampleTransaction(1, 2, 1000, 0);
    tx.setGasLimit(BigInteger.valueOf(3000001).toByteArray());
    Account receiver = createAccount(2);
    transactionPool.addTransaction(tx);
    Repository repository = transactionPool.getRepository();
    Assert.assertEquals(BigInteger.valueOf(1000000), repository.getBalance(receiver.getAddress()).asBigInteger());
}
Also used : Coin(co.rsk.core.Coin) Account(org.ethereum.core.Account) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Example 4 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class RemascProcessMinerFeesTest method validateFederatorsBalanceIsCorrect.

private void validateFederatorsBalanceIsCorrect(Repository repository, long federationReward) throws IOException, BlockStoreException {
    BridgeSupport bridgeSupport = new BridgeSupport(config, repository, null, PrecompiledContracts.BRIDGE_ADDR, null);
    RemascFederationProvider provider = new RemascFederationProvider(bridgeSupport);
    int nfederators = provider.getFederationSize();
    Coin federatorBalance = Coin.valueOf(federationReward / nfederators);
    for (int k = 0; k < nfederators; k++) {
        assertEquals(federatorBalance, repository.getBalance(provider.getFederatorAddress(k)));
    }
}
Also used : Coin(co.rsk.core.Coin) BridgeSupport(co.rsk.peg.BridgeSupport)

Example 5 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class SamplePrecompiledContract method AddBalance.

public void AddBalance(Object... args) {
    RskAddress addr = new RskAddress("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
    Coin balance = Coin.valueOf(50000);
    repository.addBalance(addr, balance);
}
Also used : Coin(co.rsk.core.Coin) RskAddress(co.rsk.core.RskAddress)

Aggregations

Coin (co.rsk.core.Coin)157 Test (org.junit.Test)85 RskAddress (co.rsk.core.RskAddress)51 RemascTransaction (co.rsk.remasc.RemascTransaction)36 BigInteger (java.math.BigInteger)35 Repository (org.ethereum.core.Repository)19 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)14 AccountState (org.ethereum.core.AccountState)14 Program (org.ethereum.vm.program.Program)13 ArrayList (java.util.ArrayList)12 Transaction (org.ethereum.core.Transaction)12 RepositorySnapshot (co.rsk.db.RepositorySnapshot)10 DataWord (org.ethereum.vm.DataWord)10 Ignore (org.junit.Ignore)10 MutableRepository (org.ethereum.db.MutableRepository)9 RepositoryLocator (co.rsk.db.RepositoryLocator)8 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)8 Keccak256 (co.rsk.crypto.Keccak256)6 Block (org.ethereum.core.Block)6 BlockStore (org.ethereum.db.BlockStore)6