From a59c695ecb8a0db4d0e158fd9fc282352a565ab7 Mon Sep 17 00:00:00 2001 From: jonny rhea Date: Tue, 19 Nov 2019 00:01:16 -0600 Subject: [PATCH] implemented test_make_a_call --- .../test/java/org/ethereum/evmc/EvmcTest.java | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java b/bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java index d657e625e..816b0671e 100644 --- a/bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java +++ b/bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java @@ -42,6 +42,7 @@ void test_return_address() { assert (gasLeft == 0); } + /** Tests callbacks: get_storage_fn & set_storage_fn */ @Test void test_counter() { EvmcVm.init(System.getProperty("user.dir") + "/../c/build/example_vm.so"); @@ -70,6 +71,7 @@ void test_counter() { assert (gasLeft == 0); } + /** Tests callbacks: get_tx_context_fn */ @Test void test_return_block_number() { EvmcVm.init(System.getProperty("user.dir") + "/../c/build/example_vm.so"); @@ -84,18 +86,18 @@ void test_return_block_number() { long gas = 200000; int depth = 0; ByteBuffer msg = - new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer(); + new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer(); byte[] code = {0x43, 0x60, 0x00, 0x52, 0x59, 0x60, 0x00, (byte) 0xf3}; // return_block_number( ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code); ByteBuffer result = - EvmcVm.execute(context, BYZANTIUM, msg, bbcode, code.length).order(ByteOrder.nativeOrder()); + EvmcVm.execute(context, BYZANTIUM, msg, bbcode, code.length).order(ByteOrder.nativeOrder()); int statusCode = result.getInt(); result.getInt(); // padding long gasLeft = result.getLong(); assert (statusCode == 0); - assert (gasLeft == gas/2); + assert (gasLeft == gas / 2); } /** Tests callbacks: get_tx_context_fn & set_storage_fn */ @@ -129,6 +131,44 @@ void test_save_return_block_number() { assert (gasLeft == gas / 2); } + /** Tests callbacks: call_fn */ + @Test + void test_make_a_call() { + EvmcVm.init(System.getProperty("user.dir") + "/../c/build/example_vm.so"); + HostContext context = new TestHostContext(); + int BYZANTIUM = 4; + int EVMC_CALL = 0; + int kind = EVMC_CALL; + char[] sender = "39bf71de1b7d7be3b51\0".toCharArray(); + char[] destination = "53cf77204eEef952e25\0".toCharArray(); + char[] value = "1\0".toCharArray(); + char[] inputData = "hello w\0".toCharArray(); + long gas = 200000; + int depth = 0; + ByteBuffer msg = + new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer(); + byte[] code = { + 0x60, + 0x00, + (byte) 0x80, + (byte) 0x80, + (byte) 0x80, + (byte) 0x80, + (byte) 0x80, + (byte) 0x80, + (byte) 0xf1 + }; // make_a_call( + ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code); + + ByteBuffer result = + EvmcVm.execute(context, BYZANTIUM, msg, bbcode, code.length).order(ByteOrder.nativeOrder()); + int statusCode = result.getInt(); + result.getInt(); // padding + long gasLeft = result.getLong(); + assert (statusCode == 0); + assert (gasLeft == 0); + } + @Test void test_EVMC_CREATE() { EvmcVm.init(System.getProperty("user.dir") + "/../c/build/example_vm.so");