Search in sources :

Example 6 with TestContract

use of co.rsk.util.TestContract in project rskj by rsksmart.

the class Web3ImplTest method callFromDefaultAddressInWallet.

@Test
public void callFromDefaultAddressInWallet() throws Exception {
    World world = new World();
    Account acc1 = new AccountBuilder(world).name("default").balance(Coin.valueOf(10000000)).build();
    Block genesis = world.getBlockByName("g00");
    TestContract greeter = TestContract.greeter();
    Transaction tx = new TransactionBuilder().sender(acc1).gasLimit(BigInteger.valueOf(100000)).gasPrice(BigInteger.ONE).data(greeter.runtimeBytecode).build();
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    world.getBlockChain().tryToConnect(block1);
    Web3Impl web3 = createWeb3Mocked(world);
    Web3.CallArguments argsForCall = new Web3.CallArguments();
    argsForCall.to = TypeConverter.toJsonHex(tx.getContractAddress().getBytes());
    argsForCall.data = TypeConverter.toJsonHex(greeter.functions.get("greet").encodeSignature());
    String result = web3.eth_call(argsForCall, "latest");
    org.junit.Assert.assertEquals("0x0000000000000000000000000000000000000000000000000000000064617665", result);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) World(co.rsk.test.World) TestContract(co.rsk.util.TestContract) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Aggregations

TestContract (co.rsk.util.TestContract)6 Test (org.junit.Test)6 ProgramResult (org.ethereum.vm.program.ProgramResult)5 Block (org.ethereum.core.Block)4 CallTransaction (org.ethereum.core.CallTransaction)4 ContractDetails (org.ethereum.db.ContractDetails)4 World (co.rsk.test.World)1 AccountBuilder (co.rsk.test.builders.AccountBuilder)1 BlockBuilder (co.rsk.test.builders.BlockBuilder)1 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)1