Search in sources :

Example 36 with TransactionBuilder

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

the class Web3ImplTest method getBlockByHashWithFullTransactionsAsResult.

@Test
public void getBlockByHashWithFullTransactionsAsResult() {
    World world = new World();
    Web3Impl web3 = createWeb3(world);
    Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(220000)).build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(0)).build();
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block genesis = world.getBlockChain().getBestBlock();
    Block block1 = new BlockBuilder(world.getBlockChain(), world.getBridgeSupportFactory(), world.getBlockStore()).trieStore(world.getTrieStore()).parent(genesis).transactions(txs).build();
    block1.setBitcoinMergedMiningHeader(new byte[] { 0x01 });
    assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
    String block1HashString = block1.getHashJsonString();
    BlockResultDTO bresult = web3.eth_getBlockByHash(block1HashString, true);
    assertNotNull(bresult);
    assertEquals(block1HashString, bresult.getHash());
    assertEquals(1, bresult.getTransactions().size());
    assertEquals(block1HashString, ((TransactionResultDTO) bresult.getTransactions().get(0)).getBlockHash());
    assertEquals(0, bresult.getUncles().size());
    assertEquals("0x0", ((TransactionResultDTO) bresult.getTransactions().get(0)).getValue());
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) BlockResultDTO(org.ethereum.rpc.dto.BlockResultDTO) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with TransactionBuilder

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

the class Web3ImplTest method callFromDefaultAddressInWallet.

@Test
public void callFromDefaultAddressInWallet() {
    World world = new World();
    Account acc1 = new AccountBuilder(world).name("default").balance(Coin.valueOf(10000000)).build();
    Block genesis = world.getBlockByName("g00");
    /* contract compiled in data attribute of tx
        contract Greeter {
            address owner;

            function greeter() public {
                owner = msg.sender;
            }

            function greet(string memory param) public pure returns (string memory) {
                return param;
            }
        }
        */
    Transaction tx = new TransactionBuilder().sender(acc1).gasLimit(BigInteger.valueOf(500000)).gasPrice(BigInteger.ONE).data("608060405234801561001057600080fd5b506101fa806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80631c8499e51461003b578063ead710c414610045575b600080fd5b610043610179565b005b6100fe6004803603602081101561005b57600080fd5b810190808035906020019064010000000081111561007857600080fd5b82018360208201111561008a57600080fd5b803590602001918460018302840111640100000000831117156100ac57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506101bb565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013e578082015181840152602081019050610123565b50505050905090810190601f16801561016b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b606081905091905056fea265627a7a723158207cbf5ab8312143442836de7909c83aec5160dae50224ecc7c16d7f35a306901e64736f6c63430005100032").build();
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block block1 = new BlockBuilder(world.getBlockChain(), world.getBridgeSupportFactory(), world.getBlockStore()).trieStore(world.getTrieStore()).parent(genesis).transactions(txs).build();
    assertTrue(world.getBlockChain().tryToConnect(block1).isSuccessful());
    Web3Impl web3 = createWeb3Mocked(world);
    CallArguments argsForCall = new CallArguments();
    argsForCall.setTo(TypeConverter.toJsonHex(tx.getContractAddress().getBytes()));
    argsForCall.setData("0xead710c40000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000");
    String result = web3.eth_call(argsForCall, "latest");
    assertEquals("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000", result);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with TransactionBuilder

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

the class TransactionModuleTest method sendRawTransaction.

private String sendRawTransaction(Web3Impl web3) {
    Account sender = new AccountBuilder().name("cow").build();
    Account receiver = new AccountBuilder().name("addr2").build();
    Transaction tx = new TransactionBuilder().sender(sender).receiver(receiver).gasPrice(BigInteger.valueOf(8)).gasLimit(BigInteger.valueOf(50000)).value(BigInteger.valueOf(7)).nonce(0).build();
    String rawData = ByteUtil.toHexString(tx.getEncoded());
    return web3.eth_sendRawTransaction(rawData);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 39 with TransactionBuilder

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

the class TxPoolModuleImplTest method createSampleTransaction.

private Transaction createSampleTransaction(int from, int to, long value, int nonce) {
    Account sender = getAccount(from);
    Account receiver = getAccount(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 40 with TransactionBuilder

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

the class ExtCodeHashTest method createTransaction.

private static Transaction createTransaction() {
    int number = 0;
    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(1000)).build();
}
Also used : Account(org.ethereum.core.Account) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Aggregations

TransactionBuilder (co.rsk.test.builders.TransactionBuilder)46 AccountBuilder (co.rsk.test.builders.AccountBuilder)41 Test (org.junit.Test)25 World (co.rsk.test.World)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 Account (org.ethereum.core.Account)17 BlockBuilder (co.rsk.test.builders.BlockBuilder)13 Transaction (org.ethereum.core.Transaction)12 ReceiptStore (org.ethereum.db.ReceiptStore)9 HashMapDB (org.ethereum.datasource.HashMapDB)6 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)6 BigInteger (java.math.BigInteger)5 ArrayList (java.util.ArrayList)5 TransactionResultDTO (org.ethereum.rpc.dto.TransactionResultDTO)5 BlockResultDTO (org.ethereum.rpc.dto.BlockResultDTO)4 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)3 Keccak256 (co.rsk.crypto.Keccak256)3 Trie (co.rsk.trie.Trie)3 Block (org.ethereum.core.Block)3 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)2