Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit f69c401

Browse files
authored
Gpactv2 Call Execution Tree Format (#129)
Added GPACT v2 call execution tree formats. Added encoding type field to GPACT v1 call execution tree format.
1 parent 7c36285 commit f69c401

27 files changed

+1467
-600
lines changed

.circleci/config.yml

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
paths:
9292
- ~/.gradle
9393

94-
unitTestsMachine:
94+
javaUnitTestsMachine:
9595
machine:
9696
image: ubuntu-2004:202107-02
9797
resource_class: large
@@ -186,7 +186,7 @@ jobs:
186186
- store_artifacts:
187187
path: ~/test-results/junit
188188

189-
intTestsMachine:
189+
javaIntTestsMachine:
190190
machine:
191191
image: ubuntu-2004:202107-02
192192
resource_class: large
@@ -223,21 +223,6 @@ jobs:
223223
working_directory: test-blockchains
224224
command: docker-compose stop
225225
when: always
226-
- run:
227-
name: Create environment for testing JS-SDK
228-
working_directory: sdk/js
229-
background: true
230-
command: npm install && docker-compose up
231-
- run: sleep 30
232-
- run:
233-
name: Test JS-SDK
234-
working_directory: sdk/js
235-
command: node ./test.js
236-
- run:
237-
name: Stop environment for testing JS-SDK
238-
working_directory: sdk/js
239-
command: docker-compose stop
240-
when: always
241226
- run:
242227
name: Logs from bc31
243228
working_directory: test-blockchains
@@ -296,6 +281,58 @@ jobs:
296281
- store_artifacts:
297282
path: ~/test-results/junit
298283

284+
typescriptIntTestsMachine:
285+
machine:
286+
image: ubuntu-2004:202107-02
287+
resource_class: large
288+
steps:
289+
# The home directory is: /home/circleci/project
290+
# gpact is cloned to: /home/circleci/project/.
291+
# web3j is cloned to: /home/circleci/web3j-abi
292+
- prepare
293+
- run:
294+
name: Build web3j
295+
command: |
296+
# Build our Web3j
297+
cd ../web3j-abi
298+
./gradlew --parallel --stacktrace --info --build-cache installDist
299+
- run:
300+
name: Create Relayer containers
301+
working_directory: services/relayer
302+
command: make docker
303+
- run:
304+
name: Create Message Store container
305+
working_directory: services/message-store
306+
command: make docker
307+
- run:
308+
name: Create and Start blockchains
309+
working_directory: sdk/js
310+
background: true
311+
command: docker-compose build && docker-compose up
312+
- run:
313+
name: Build Solidity code for use with TypeScript compile
314+
command: ./gradlew build -x test -x intTest -x perfTest
315+
- run:
316+
name: Create environment for testing JS-SDK
317+
working_directory: sdk/js
318+
background: true
319+
command: npm install
320+
- run: sleep 30
321+
- run:
322+
name: Test JS-SDK
323+
working_directory: sdk/js
324+
command: node ./test.js
325+
- run:
326+
name: Stop environment for testing JS-SDK
327+
working_directory: sdk/js
328+
command: docker-compose stop
329+
when: always
330+
- run:
331+
name: Remove blockchains
332+
working_directory: sdk/js
333+
command: docker-compose down
334+
when: always
335+
299336
perfTestsMachine:
300337
machine:
301338
image: ubuntu-2004:202107-02
@@ -465,17 +502,21 @@ workflows:
465502
- relayer-test:
466503
requires:
467504
- relayer-build
468-
- unitTestsMachine:
505+
- javaUnitTestsMachine:
469506
requires:
470507
- relayer-build
471508
- javasdk-build
472-
- intTestsMachine:
509+
- javaIntTestsMachine:
473510
requires:
474511
- relayer-build
475512
- javasdk-build
476513
- perfTestsMachine:
477514
requires:
478515
- relayer-build
479516
- javasdk-build
517+
- typescriptIntTestsMachine:
518+
requires:
519+
- relayer-build
520+
- javasdk-build
480521

481522

commontest/java/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ dependencies {
2020
implementation group: 'org.apache.tuweni', name: 'tuweni-bytes', version: '1.0.0'
2121
// https://mvnrepository.com/artifact/org.apache.tuweni/tuweni-units
2222
implementation group: 'org.apache.tuweni', name: 'tuweni-units', version: '1.0.0'
23+
24+
implementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitVersion
25+
2326
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package net.consensys.gpact.functioncall.common;
2+
3+
import java.math.BigInteger;
4+
import net.consensys.gpact.common.BlockchainId;
5+
import net.consensys.gpact.common.test.AbstractWeb3Test;
6+
import net.consensys.gpact.functioncall.CallExecutionTree;
7+
import net.consensys.gpact.functioncall.CallExecutionTreeException;
8+
import org.junit.jupiter.api.Test;
9+
10+
public abstract class CallExecutionTreeTestCommon extends AbstractWeb3Test {
11+
public static byte[] BIG32 =
12+
new byte[] {
13+
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
14+
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
15+
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
16+
0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x01
17+
};
18+
BlockchainId blockchainId1 = new BlockchainId(new BigInteger(BIG32));
19+
BlockchainId blockchainId2 = new BlockchainId(blockchainId1.asBigInt().add(BigInteger.ONE));
20+
BlockchainId blockchainId3 = new BlockchainId(blockchainId2.asBigInt().add(BigInteger.ONE));
21+
BlockchainId blockchainId4 = new BlockchainId(blockchainId3.asBigInt().add(BigInteger.ONE));
22+
BlockchainId blockchainId5 = new BlockchainId(blockchainId4.asBigInt().add(BigInteger.ONE));
23+
BlockchainId blockchainId6 = new BlockchainId(blockchainId5.asBigInt().add(BigInteger.ONE));
24+
BlockchainId blockchainId7 = new BlockchainId(blockchainId6.asBigInt().add(BigInteger.ONE));
25+
BlockchainId blockchainId8 = new BlockchainId(blockchainId7.asBigInt().add(BigInteger.ONE));
26+
27+
public static String BIG19 = "0x0102030405060708090a0b0c0d0e0f10111213";
28+
String contract1 = BIG19 + "01";
29+
String contract2 = BIG19 + "02";
30+
String contract3 = BIG19 + "03";
31+
String contract4 = BIG19 + "04";
32+
String contract5 = BIG19 + "05";
33+
String contract6 = BIG19 + "06";
34+
String contract7 = BIG19 + "07";
35+
String contract8 = BIG19 + "08";
36+
37+
String noFuncData = "";
38+
String onlyFunctionSelection = "0x31323334";
39+
String function1 = "0x410203040a";
40+
String function2 = "0x410203040a010203040506070809aabb";
41+
String function3 = "0x410203040a010203040506070809aabc";
42+
String function4 = "0x410203040a010203040506070809aabd";
43+
String function5 = "0x410203040a010203040506070809aa02";
44+
String function6 = "0x410203040a010203040506070809aa03";
45+
String function7 = "0x410203040a010203040506070809aa05";
46+
String function8 = "0x410203040a010203040506070809aa09";
47+
48+
abstract void checkJavaEncodeDecode(final CallExecutionTree seg)
49+
throws CallExecutionTreeException;
50+
51+
@Test
52+
public void singleFunc() throws CallExecutionTreeException {
53+
CallExecutionTree seg = new CallExecutionTree(blockchainId1, contract1, function1);
54+
checkJavaEncodeDecode(seg);
55+
}
56+
57+
@Test
58+
public void singleFuncNoFuncData() throws CallExecutionTreeException {
59+
CallExecutionTree seg = new CallExecutionTree(blockchainId1, contract1, noFuncData);
60+
checkJavaEncodeDecode(seg);
61+
}
62+
63+
@Test
64+
public void singleFuncOnlyFunctionSelector() throws CallExecutionTreeException {
65+
CallExecutionTree seg = new CallExecutionTree(blockchainId1, contract1, onlyFunctionSelection);
66+
checkJavaEncodeDecode(seg);
67+
}
68+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package net.consensys.gpact.functioncall.common;
2+
3+
import java.math.BigInteger;
4+
import java.util.ArrayList;
5+
import net.consensys.gpact.common.Tuple;
6+
import net.consensys.gpact.functioncall.CallExecutionTree;
7+
import net.consensys.gpact.functioncall.CallExecutionTreeException;
8+
import org.apache.tuweni.bytes.Bytes;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.Test;
11+
12+
public abstract class CallExecutionTreeV1TestCommon extends CallExecutionTreeTestCommon {
13+
abstract Tuple<BigInteger, String, String> extractFunction(byte[] encodedCallTree, int[] callPath)
14+
throws CallExecutionTreeException;
15+
16+
public void checkJavaEncodeDecode(final CallExecutionTree seg) throws CallExecutionTreeException {
17+
byte[] encoded = seg.encode(CallExecutionTree.ENCODING_V1);
18+
CallExecutionTree.dump(encoded);
19+
}
20+
21+
@Test
22+
public void rootOneSeg() throws Exception {
23+
CallExecutionTree seg = new CallExecutionTree(blockchainId2, contract2, function2);
24+
ArrayList<CallExecutionTree> rootCalls1 = new ArrayList<>();
25+
rootCalls1.add(seg);
26+
CallExecutionTree root = new CallExecutionTree(blockchainId1, contract1, function1, rootCalls1);
27+
28+
byte[] encoded = root.encode();
29+
Tuple<BigInteger, String, String> func = extractFunction(encoded, new int[] {0});
30+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId1.toPlainString());
31+
Assertions.assertEquals(func.getSecond(), contract1);
32+
Assertions.assertEquals(func.getThird(), function1);
33+
34+
func = extractFunction(encoded, new int[] {1});
35+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId2.toPlainString());
36+
Assertions.assertEquals(func.getSecond(), contract2);
37+
Assertions.assertEquals(func.getThird(), function2);
38+
}
39+
40+
@Test
41+
public void rootTwoSeg() throws Exception {
42+
CallExecutionTree seg1 = new CallExecutionTree(blockchainId2, contract2, function2);
43+
CallExecutionTree seg2 = new CallExecutionTree(blockchainId3, contract3, function3);
44+
ArrayList<CallExecutionTree> rootCalls1 = new ArrayList<>();
45+
rootCalls1.add(seg1);
46+
rootCalls1.add(seg2);
47+
CallExecutionTree root = new CallExecutionTree(blockchainId1, contract1, function1, rootCalls1);
48+
root.toString();
49+
50+
byte[] encoded = root.encode();
51+
Tuple<BigInteger, String, String> func = extractFunction(encoded, new int[] {0});
52+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId1.toPlainString());
53+
Assertions.assertEquals(func.getSecond(), contract1);
54+
Assertions.assertEquals(func.getThird(), function1);
55+
56+
func = extractFunction(encoded, new int[] {1});
57+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId2.toPlainString());
58+
Assertions.assertEquals(func.getSecond(), contract2);
59+
Assertions.assertEquals(func.getThird(), function2);
60+
61+
func = extractFunction(encoded, new int[] {2});
62+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId3.toPlainString());
63+
Assertions.assertEquals(func.getSecond(), contract3);
64+
Assertions.assertEquals(func.getThird(), function3);
65+
}
66+
67+
@Test
68+
public void complex() throws Exception {
69+
CallExecutionTree seg1 = new CallExecutionTree(blockchainId2, contract2, function2);
70+
CallExecutionTree seg2 = new CallExecutionTree(blockchainId3, contract3, function3);
71+
72+
CallExecutionTree seg3 = new CallExecutionTree(blockchainId5, contract5, function5);
73+
ArrayList<CallExecutionTree> seg4Calls = new ArrayList<>();
74+
seg4Calls.add(seg1);
75+
seg4Calls.add(seg2);
76+
CallExecutionTree seg4 = new CallExecutionTree(blockchainId4, contract4, function4, seg4Calls);
77+
ArrayList<CallExecutionTree> seg5Calls = new ArrayList<>();
78+
seg5Calls.add(seg4);
79+
CallExecutionTree seg5 = new CallExecutionTree(blockchainId6, contract6, function6, seg5Calls);
80+
CallExecutionTree seg6 = new CallExecutionTree(blockchainId7, contract7, function7);
81+
CallExecutionTree seg7 = new CallExecutionTree(blockchainId8, contract8, function8);
82+
83+
ArrayList<CallExecutionTree> rootCalls1 = new ArrayList<>();
84+
rootCalls1.add(seg3);
85+
rootCalls1.add(seg5);
86+
rootCalls1.add(seg6);
87+
rootCalls1.add(seg7);
88+
CallExecutionTree root = new CallExecutionTree(blockchainId1, contract1, function1, rootCalls1);
89+
root.toString();
90+
91+
byte[] encoded = root.encode();
92+
Tuple<BigInteger, String, String> func = extractFunction(encoded, new int[] {0});
93+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId1.toPlainString());
94+
Assertions.assertEquals(func.getSecond(), contract1);
95+
Assertions.assertEquals(func.getThird(), function1);
96+
97+
func = extractFunction(encoded, new int[] {1});
98+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId5.toPlainString());
99+
Assertions.assertEquals(func.getSecond(), contract5);
100+
Assertions.assertEquals(func.getThird(), function5);
101+
102+
func = extractFunction(encoded, new int[] {2, 0});
103+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId6.toPlainString());
104+
Assertions.assertEquals(func.getSecond(), contract6);
105+
Assertions.assertEquals(func.getThird(), function6);
106+
107+
func = extractFunction(encoded, new int[] {2, 1, 0});
108+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId4.toPlainString());
109+
Assertions.assertEquals(func.getSecond(), contract4);
110+
Assertions.assertEquals(func.getThird(), function4);
111+
112+
func = extractFunction(encoded, new int[] {2, 1, 1});
113+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId2.toPlainString());
114+
Assertions.assertEquals(func.getSecond(), contract2);
115+
Assertions.assertEquals(func.getThird(), function2);
116+
117+
func = extractFunction(encoded, new int[] {2, 1, 2});
118+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId3.toPlainString());
119+
Assertions.assertEquals(func.getSecond(), contract3);
120+
Assertions.assertEquals(func.getThird(), function3);
121+
122+
func = extractFunction(encoded, new int[] {3});
123+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId7.toPlainString());
124+
Assertions.assertEquals(func.getSecond(), contract7);
125+
Assertions.assertEquals(func.getThird(), function7);
126+
127+
func = extractFunction(encoded, new int[] {4});
128+
Assertions.assertEquals(func.getFirst().toString(16), blockchainId8.toPlainString());
129+
Assertions.assertEquals(func.getSecond(), contract8);
130+
Assertions.assertEquals(func.getThird(), function8);
131+
}
132+
133+
@Test
134+
public void checkCallTreeFromJs() throws Exception {
135+
String callTree =
136+
"0x000100000009000000e3000000000000000000000000000000000000000000000000000000000000001fff7f799bd183b3efd57b5a964cb7cbfec4fbd84400a469f36dcf0000000000000000000000009f2758f2e0e9a5c4ba389035c4c2895232d84b460000000000000000000000000e565f77c56e35d812a1f02356d263320012b3d700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000944bde1f618e8d7caec2ec10861f6a2b1ef092db000000000000000000000000000000000000000000000000000000000000000020705188c0cf57f6890e2fcd5fb6d21e529071fa5a0084123756cd000000000000000000000000944bde1f618e8d7caec2ec10861f6a2b1ef092db00000000000000000000000000000000000000000000000000000000000000640000000000000000000000009f2758f2e0e9a5c4ba389035c4c2895232d84b46000000000000000000000000bb7c00f1dd65bce0e10a6b6228dff430c9c1c871";
137+
Bytes callTreeBytes = Bytes.fromHexString(callTree);
138+
byte[] callTreeB = callTreeBytes.toArray();
139+
System.out.println(CallExecutionTreeEncoderV1.dump(callTreeB));
140+
141+
Tuple<BigInteger, String, String> root = extractFunction(callTreeB, new int[] {0});
142+
Assertions.assertEquals("1f", root.getFirst().toString(16));
143+
Assertions.assertEquals("0xff7f799bd183b3efd57b5a964cb7cbfec4fbd844", root.getSecond());
144+
Assertions.assertEquals(
145+
"0x69f36dcf0000000000000000000000009f2758f2e0e9a5c4ba389035c4c2895232d84b460000000000000000000000000e565f77c56e35d812a1f02356d263320012b3d700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000944bde1f618e8d7caec2ec10861f6a2b1ef092db",
146+
root.getThird());
147+
148+
Tuple<BigInteger, String, String> seg = extractFunction(callTreeB, new int[] {1});
149+
Assertions.assertEquals("20", seg.getFirst().toString(16));
150+
Assertions.assertEquals("0x705188c0cf57f6890e2fcd5fb6d21e529071fa5a", seg.getSecond());
151+
Assertions.assertEquals(
152+
"0x123756cd000000000000000000000000944bde1f618e8d7caec2ec10861f6a2b1ef092db00000000000000000000000000000000000000000000000000000000000000640000000000000000000000009f2758f2e0e9a5c4ba389035c4c2895232d84b46000000000000000000000000bb7c00f1dd65bce0e10a6b6228dff430c9c1c871",
153+
seg.getThird());
154+
}
155+
}

0 commit comments

Comments
 (0)