Search in sources :

Example 1 with TestContract

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

the class ProgramTest method returnDataCopyTest.

@Test
public void returnDataCopyTest() {
    TestContract contract = TestContract.returnDataTest();
    ProgramResult result = contract.executeFunction("testCopy", BigInteger.ZERO);
    Assert.assertFalse(result.isRevert());
    Assert.assertNull(result.getException());
    Assert.assertArrayEquals(new Object[] { LOREM_IPSUM }, contract.functions.get("testCopy").decodeResult(result.getHReturn()));
}
Also used : TestContract(co.rsk.util.TestContract) ProgramResult(org.ethereum.vm.program.ProgramResult) Test(org.junit.Test)

Example 2 with TestContract

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

the class ReversibleTransactionExecutorTest method executeTransactionHello.

@Test
public void executeTransactionHello() {
    TestContract hello = TestContract.hello();
    CallTransaction.Function helloFn = hello.functions.get("hello");
    ContractDetails contract = contractRunner.addContract(hello.runtimeBytecode);
    RskAddress from = RskAddress.nullAddress();
    byte[] gasPrice = Hex.decode("00");
    byte[] value = Hex.decode("00");
    byte[] gasLimit = Hex.decode("f424");
    Block bestBlock = factory.getBlockchain().getBestBlock();
    ProgramResult result = reversibleTransactionExecutor.executeTransaction(bestBlock, bestBlock.getCoinbase(), gasPrice, gasLimit, contract.getAddress(), value, helloFn.encode(), from.getBytes());
    Assert.assertNull(result.getException());
    Assert.assertArrayEquals(new String[] { "chinchilla" }, helloFn.decodeResult(result.getHReturn()));
}
Also used : TestContract(co.rsk.util.TestContract) ProgramResult(org.ethereum.vm.program.ProgramResult) CallTransaction(org.ethereum.core.CallTransaction) Block(org.ethereum.core.Block) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Example 3 with TestContract

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

the class ReversibleTransactionExecutorTest method executeTransactionGreeter.

@Test
public void executeTransactionGreeter() {
    TestContract greeter = TestContract.greeter();
    CallTransaction.Function greeterFn = greeter.functions.get("greet");
    ContractDetails contract = contractRunner.addContract(greeter.runtimeBytecode);
    RskAddress from = RskAddress.nullAddress();
    byte[] gasPrice = Hex.decode("00");
    byte[] value = Hex.decode("00");
    byte[] gasLimit = Hex.decode("f424");
    Block bestBlock = factory.getBlockchain().getBestBlock();
    ProgramResult result = reversibleTransactionExecutor.executeTransaction(bestBlock, bestBlock.getCoinbase(), gasPrice, gasLimit, contract.getAddress(), value, greeterFn.encode("greet me"), from.getBytes());
    Assert.assertNull(result.getException());
    Assert.assertArrayEquals(new String[] { "greet me" }, greeterFn.decodeResult(result.getHReturn()));
}
Also used : TestContract(co.rsk.util.TestContract) ProgramResult(org.ethereum.vm.program.ProgramResult) CallTransaction(org.ethereum.core.CallTransaction) Block(org.ethereum.core.Block) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Example 4 with TestContract

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

the class ReversibleTransactionExecutorTest method executeTransactionGreeterOtherSender.

@Test
public void executeTransactionGreeterOtherSender() {
    TestContract greeter = TestContract.greeter();
    CallTransaction.Function greeterFn = greeter.functions.get("greet");
    ContractDetails contract = contractRunner.addContract(greeter.runtimeBytecode);
    // someone else
    RskAddress from = new RskAddress("0000000000000000000000000000000000000023");
    byte[] gasPrice = Hex.decode("00");
    byte[] value = Hex.decode("00");
    byte[] gasLimit = Hex.decode("f424");
    Block bestBlock = factory.getBlockchain().getBestBlock();
    ProgramResult result = reversibleTransactionExecutor.executeTransaction(bestBlock, bestBlock.getCoinbase(), gasPrice, gasLimit, contract.getAddress(), value, greeterFn.encode("greet me"), from.getBytes());
    Assert.assertTrue(result.isRevert());
}
Also used : TestContract(co.rsk.util.TestContract) ProgramResult(org.ethereum.vm.program.ProgramResult) CallTransaction(org.ethereum.core.CallTransaction) Block(org.ethereum.core.Block) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Example 5 with TestContract

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

the class ReversibleTransactionExecutorTest method executeTransactionCountCallsMultipleTimes.

@Test
public void executeTransactionCountCallsMultipleTimes() {
    TestContract countcalls = TestContract.countcalls();
    CallTransaction.Function callsFn = countcalls.functions.get("calls");
    ContractDetails contract = contractRunner.addContract(countcalls.runtimeBytecode);
    // someone else
    RskAddress from = new RskAddress("0000000000000000000000000000000000000023");
    byte[] gasPrice = Hex.decode("00");
    byte[] value = Hex.decode("00");
    byte[] gasLimit = Hex.decode("f424");
    Block bestBlock = factory.getBlockchain().getBestBlock();
    ProgramResult result = reversibleTransactionExecutor.executeTransaction(bestBlock, bestBlock.getCoinbase(), gasPrice, gasLimit, contract.getAddress(), value, callsFn.encodeSignature(), from.getBytes());
    Assert.assertNull(result.getException());
    Assert.assertArrayEquals(new String[] { "calls: 1" }, callsFn.decodeResult(result.getHReturn()));
    ProgramResult result2 = reversibleTransactionExecutor.executeTransaction(bestBlock, bestBlock.getCoinbase(), gasPrice, gasLimit, contract.getAddress(), value, callsFn.encodeSignature(), from.getBytes());
    Assert.assertNull(result2.getException());
    Assert.assertArrayEquals(new String[] { "calls: 1" }, callsFn.decodeResult(result2.getHReturn()));
}
Also used : TestContract(co.rsk.util.TestContract) ProgramResult(org.ethereum.vm.program.ProgramResult) CallTransaction(org.ethereum.core.CallTransaction) Block(org.ethereum.core.Block) ContractDetails(org.ethereum.db.ContractDetails) 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