Search in sources :

Example 26 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class RskTestFactory method executeRawContract.

public ProgramResult executeRawContract(byte[] bytecode, byte[] encodedCall, BigInteger value) {
    Account sender = new AccountBuilder(getBlockchain()).name("sender").balance(Coin.valueOf(10000000L)).build();
    BigInteger nonceCreate = getRepository().getNonce(sender.getAddress());
    Transaction creationTx = new TransactionBuilder().gasLimit(BigInteger.valueOf(3000000)).sender(sender).data(bytecode).nonce(nonceCreate.longValue()).build();
    executeTransaction(creationTx);
    BigInteger nonceExecute = getRepository().getNonce(sender.getAddress());
    Transaction transaction = new TransactionBuilder().gasLimit(BigInteger.valueOf(3000000)).sender(sender).receiverAddress(creationTx.getContractAddress().getBytes()).data(encodedCall).nonce(nonceExecute.longValue()).value(value).build();
    return executeTransaction(transaction).getResult();
}
Also used : BigInteger(java.math.BigInteger) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 27 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class TransactionFactoryHelper method createSampleTransaction.

public static Transaction createSampleTransaction(long nonce) {
    Account sender = new AccountBuilder().name("sender").build();
    Account receiver = new AccountBuilder().name("receiver").build();
    Transaction tx = new TransactionBuilder().nonce(nonce).sender(sender).receiver(receiver).value(BigInteger.TEN).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 28 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class TransactionFactoryHelper method createSampleTransaction.

public static Transaction createSampleTransaction(int from, int to, long value, int nonce) {
    Account sender = createAccount(from);
    Account receiver = createAccount(to);
    Transaction tx = new TransactionBuilder().sender(sender).receiver(receiver).nonce(nonce).value(BigInteger.valueOf(value)).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder)

Example 29 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class TransactionBuilderTest method buildTransaction.

@Test
public void buildTransaction() {
    Account sender = new AccountBuilder().name("sender").build();
    Account receiver = new AccountBuilder().name("receiver").build();
    Transaction tx = new TransactionBuilder().sender(sender).receiver(receiver).value(BigInteger.TEN).nonce(2).build();
    Assert.assertNotNull(tx);
    Assert.assertArrayEquals(sender.getAddress().getBytes(), tx.getSender().getBytes());
    Assert.assertArrayEquals(receiver.getAddress().getBytes(), tx.getReceiveAddress().getBytes());
    Assert.assertEquals(BigInteger.TEN, tx.getValue().asBigInteger());
    Assert.assertEquals(BigInteger.ONE, tx.getGasPrice().asBigInteger());
    Assert.assertEquals(BigInteger.valueOf(2), new BigInteger(1, tx.getNonce()));
    Assert.assertEquals(BigInteger.valueOf(21000), new BigInteger(1, tx.getGasLimit()));
    Assert.assertNotNull(tx.getData());
    Assert.assertEquals(0, tx.getData().length);
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) BigInteger(java.math.BigInteger) AccountBuilder(co.rsk.test.builders.AccountBuilder) Test(org.junit.Test)

Aggregations

TransactionBuilder (co.rsk.test.builders.TransactionBuilder)29 AccountBuilder (co.rsk.test.builders.AccountBuilder)24 Test (org.junit.Test)17 World (co.rsk.test.World)15 BlockBuilder (co.rsk.test.builders.BlockBuilder)13 Account (org.ethereum.core.Account)10 Transaction (org.ethereum.core.Transaction)9 TransactionResultDTO (org.ethereum.rpc.dto.TransactionResultDTO)5 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)3 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)3 BigInteger (java.math.BigInteger)3 HashMapDB (org.ethereum.datasource.HashMapDB)3 ReceiptStore (org.ethereum.db.ReceiptStore)3 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)3 TransactionReceiptDTO (org.ethereum.rpc.dto.TransactionReceiptDTO)2 TestContract (co.rsk.util.TestContract)1 ArrayList (java.util.ArrayList)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1