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()));
}
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()));
}
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()));
}
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());
}
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()));
}
Aggregations