Search in sources :

Example 21 with AccountBuilder

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

the class AccountBuilderTest method createAccountWithBalanceAndCode.

@Test
public void createAccountWithBalanceAndCode() {
    World world = new World();
    byte[] code = new byte[] { 0x01, 0x02, 0x03 };
    Coin balance = Coin.valueOf(10);
    Account account = new AccountBuilder(world).name("acc1").balance(balance).code(code).build();
    Assert.assertNotNull(account);
    Assert.assertTrue(account.getEcKey().hasPrivKey());
    Assert.assertEquals(balance, world.getRepository().getBalance(account.getAddress()));
    Assert.assertArrayEquals(code, world.getRepository().getCode(account.getAddress()));
}
Also used : Coin(co.rsk.core.Coin) Account(org.ethereum.core.Account) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) Test(org.junit.Test)

Example 22 with AccountBuilder

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

the class CallContractTest method callContractReturningOne.

@Test
public void callContractReturningOne() {
    World world = new World();
    byte[] code = new byte[] { 0x60, 0x01, 0x60, 0x00, 0x52, 0x60, 0x20, 0x60, 0x00, (byte) 0xf3 };
    Account account = new AccountBuilder(world).name("acc1").code(code).build();
    ProgramResult result = callContract(world, account.getAddress(), new byte[0]);
    Assert.assertNotNull(result);
    byte[] value = result.getHReturn();
    Assert.assertNotNull(value);
    Assert.assertEquals(32, value.length);
    Assert.assertEquals(BigInteger.ONE, new BigInteger(1, value));
}
Also used : ProgramResult(org.ethereum.vm.program.ProgramResult) BigInteger(java.math.BigInteger) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) Test(org.junit.Test)

Example 23 with AccountBuilder

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

the class ImmutableTransactionTest method createImmutableTransaction.

private static Transaction createImmutableTransaction() {
    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).immutable().build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 24 with AccountBuilder

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

the class WriterMessageRecorderTest method createEthMessage.

public static Message createEthMessage() {
    Account acc1 = new AccountBuilder().name("acc1").build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx = new co.rsk.test.builders.TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    return new TransactionsMessage(config, tx);
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 25 with AccountBuilder

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

the class MessageTest method createTransaction.

private static Transaction createTransaction(int number) {
    AccountBuilder acbuilder = new AccountBuilder();
    acbuilder.name("sender" + number);
    Account sender = acbuilder.build();
    acbuilder.name("receiver" + number);
    Account receiver = acbuilder.build();
    TransactionBuilder txbuilder = new TransactionBuilder();
    return txbuilder.sender(sender).receiver(receiver).value(BigInteger.valueOf(number * 1000 + 1000)).build();
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Aggregations

AccountBuilder (co.rsk.test.builders.AccountBuilder)49 Test (org.junit.Test)37 World (co.rsk.test.World)33 BlockBuilder (co.rsk.test.builders.BlockBuilder)26 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)24 Account (org.ethereum.core.Account)14 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)13 ArrayList (java.util.ArrayList)12 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)10 SimpleEthereum (org.ethereum.rpc.Simples.SimpleEthereum)8 Transaction (org.ethereum.core.Transaction)7 TransactionResultDTO (org.ethereum.rpc.dto.TransactionResultDTO)5 BigInteger (java.math.BigInteger)4 HashMapDB (org.ethereum.datasource.HashMapDB)4 ReceiptStore (org.ethereum.db.ReceiptStore)4 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)4 RskAddress (co.rsk.core.RskAddress)3 Coin (co.rsk.core.Coin)2 TransactionReceiptDTO (org.ethereum.rpc.dto.TransactionReceiptDTO)2 TestContract (co.rsk.util.TestContract)1