Skip to content

Commit

Permalink
implemented test_make_a_call
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhea committed Nov 20, 2019
1 parent fd52565 commit a59c695
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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 */
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit a59c695

Please sign in to comment.