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