Skip to content

Commit 5d67e2d

Browse files
redlarvaibrizsabin
andauthored
fix: e2e and integration test cleanup (#703)
* fix: e2e and integration test cleanup * fix: update config for archway e2e test --------- Co-authored-by: ibrizsabin <101165234+ibrizsabin@users.noreply.github.com>
1 parent a3278d0 commit 5d67e2d

19 files changed

+181
-73
lines changed

.gitmodules

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
[submodule "xcall-multi"]
66
path = xcall-multi
77
url = https://github.com/icon-project/xcall-multi.git
8+
branch = main
9+

contracts/javascore/settings.gradle

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@ project(':mockclient').name = "mockclient"
1818

1919
include(':mockapp')
2020
project(':mockapp').projectDir = file("modules/mockapp")
21-
project(':mockapp').name = "mockapp"
22-
23-
includeBuild "../../xcall-multi/contracts/javascore/"
21+
project(':mockapp').name = "mockapp"

contracts/javascore/xcall-connection/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
version = '0.1.0'
22

33
dependencies {
4+
implementation group: 'xyz.venture23', name: 'xcall-lib', version: '0.1.1'
45
implementation project(':lib')
56
implementation project(':score-util')
6-
implementation 'xcall:xcall'
77
testImplementation project(':test-lib')
88
}
99

scripts/build-xcall.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#!/bin/sh
22

33
set -e
4-
cd xCall
4+
mkdir -p artifacts/icon
5+
mkdir -p artifacts/archway
6+
7+
echo "building xcall contracts..."
8+
cd xcall-multi
59
./scripts/optimize-cosmwasm.sh
10+
./scripts/optimize-jar.sh
611
echo "$PWD"
7-
cp artifacts/archway/*.wasm ../artifacts/archway/
12+
cp artifacts/archway/*.wasm ../artifacts/archway/
13+
cp artifacts/icon/*.jar ../artifacts/icon/
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -e
3+
echo "cleaning contract directories..."
4+
find artifacts/icon -type f -exec rm {} \;
5+
find artifacts/archway -type f -exec rm {} \;
6+
echo "building contracts..."
7+
./scripts/build-xcall.sh
8+
./scripts/optimize-cosmwasm.sh
9+
./scripts/optimize-jar.sh
10+
echo "executing e2e test..."
11+
go test -v ./test/e2e -timeout 0 -count=1
12+
13+

scripts/optimize-cosmwasm.sh

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ rename_wasm_with_version() {
6464
local wasm_file="artifacts/archway/${project_path//-/_}.wasm"
6565

6666
if [[ -f "$wasm_file" ]]; then
67+
cp "$wasm_file" "${wasm_file%.wasm}_latest.wasm"
6768
mv "$wasm_file" "${wasm_file%.wasm}_${version}.wasm"
6869
echo "Renamed: ${wasm_file} -> ${wasm_file%.wasm}_${version}.wasm"
6970
else

scripts/optimize-jar.sh

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ cd contracts/javascore
77
./gradlew clean optimizedJar
88
cd -
99

10-
cd xCall/contracts/javascore
11-
./gradlew clean optimizedJar
12-
cd -
10+
1311
for jar in $(find . -type f -name "*optimized.jar" | grep /build/libs/); do
14-
NAME=$(basename "$jar" .jar)${SUFFIX}.jar
12+
NAME=$(basename "$jar" .jar).jar
1513
echo "Creating intermediate hash for ${NAME}..."
1614
sha256sum -- "$jar" | tee -a artifacts/icon/checksums_intermediate.txt
17-
echo "Copying $NAME ..."
15+
echo "Copying $NAME"
1816
cp "$jar" "artifacts/icon/$NAME"
17+
cp "$jar" "artifacts/icon/${NAME%%-[0-9]*.[0-9]*.[0-9]*-optimized.jar}-latest.jar"
1918
done
19+
20+
21+
22+

test/chains/chain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Chain interface {
3636
FindTargetXCallMessage(ctx context.Context, target Chain, height uint64, to string) (*XCallResponse, error)
3737
ConfigureBaseConnection(ctx context.Context, connection XCallConnection) (context.Context, error)
3838
SendPacketXCall(ctx context.Context, keyName, _to string, data, rollback []byte) (context.Context, error)
39-
IsPacketReceived(ctx context.Context, params map[string]interface{}) bool
39+
IsPacketReceived(ctx context.Context, params map[string]interface{}, order ibc.Order) bool
4040
XCall(ctx context.Context, targetChain Chain, keyName, _to string, data, rollback []byte) (*XCallResponse, error)
4141
CheckForTimeout(ctx context.Context, src Chain, params map[string]interface{}, listener EventListener) (context.Context, error)
4242
EOAXCall(ctx context.Context, targetChain Chain, keyName, _to string, data []byte, sources, destinations []string) (string, string, string, error)

test/chains/cosmos/localnet.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,18 @@ func (c *CosmosLocalnet) findSn(tx *TxResul, eType string) string {
376376
}
377377

378378
// IsPacketReceived returns the receipt of the packet sent to the target chain
379-
func (c *CosmosLocalnet) IsPacketReceived(ctx context.Context, params map[string]interface{}) bool {
379+
func (c *CosmosLocalnet) IsPacketReceived(ctx context.Context, params map[string]interface{}, order ibc.Order) bool {
380+
if order == ibc.Ordered {
381+
sequence := params["sequence"].(uint64)
382+
ctx, err := c.QueryContract(ctx, c.IBCAddresses["ibc"], chains.GetNextSequenceReceive, params)
383+
if err != nil {
384+
fmt.Printf("Error--%v\n", err)
385+
return false
386+
}
387+
response := ctx.Value("query-result").(map[string]interface{})
388+
fmt.Printf("response[\"data\"]----%v", response["data"])
389+
return sequence < uint64(response["data"].(float64))
390+
}
380391
ctx, err := c.QueryContract(ctx, c.IBCAddresses["ibc"], chains.HasPacketReceipt, params)
381392
if err != nil {
382393
fmt.Printf("Error--%v\n", err)
@@ -512,11 +523,11 @@ func (c *CosmosLocalnet) executeContract(ctx context.Context, contractAddress, k
512523
txHash, err := c.getFullNode().ExecTx(ctx, keyName,
513524
"wasm", "execute", contractAddress, `{"`+methodName+`":`+param+`}`, "--gas", "auto")
514525
if err != nil || txHash == "" {
515-
return nil, err
526+
return ctx, err
516527
}
517528
tx, err := c.getTransaction(txHash)
518529
if err != nil {
519-
return nil, err
530+
return ctx, err
520531
}
521532
return context.WithValue(ctx, "txResult", tx), nil
522533
}

test/chains/cosmos/params.go

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func (c *CosmosLocalnet) GetQueryParam(method string, params map[string]interfac
3333
case chains.HasPacketReceipt:
3434
query = Query{HasPacketReceipt: &params}
3535
break
36+
case chains.GetNextSequenceReceive:
37+
query = Query{GetNextSequenceReceive: &map[string]interface{}{
38+
"channel_id": params["channel_id"],
39+
"port_id": params["port_id"],
40+
}}
41+
break
3642
case chains.GetClientState:
3743
query = Query{GetClientState: &params}
3844
break

test/chains/cosmos/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Query struct {
3838
GetProtocolFee *GetProtocolFee `json:"get_protocol_fee,omitempty"`
3939
GetNextClientSequence *map[string]interface{} `json:"get_next_client_sequence,omitempty"`
4040
HasPacketReceipt *map[string]interface{} `json:"has_packet_receipt,omitempty"`
41+
GetNextSequenceReceive *map[string]interface{} `json:"get_next_sequence_receive,omitempty"`
4142
GetConnection *map[string]interface{} `json:"get_connection,omitempty"`
4243
GetChannel *map[string]interface{} `json:"get_channel,omitempty"`
4344
GetNextConnectionSequence *map[string]interface{} `json:"get_next_connection_sequence,omitempty"`

test/chains/icon/localnet.go

+42-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io"
1212
"log"
1313
"math/big"
14+
"regexp"
1415
"strconv"
1516
"strings"
1617
"sync"
@@ -511,7 +512,7 @@ func (c *IconLocalnet) ConfigureBaseConnection(ctx context.Context, connection c
511512
if err != nil {
512513
return nil, err
513514
}
514-
params = []byte(`{"nid":"` + connection.CounterpartyNid + `","connection":"` + connectionAddress + `"}`)
515+
params = []byte(`{"_nid":"` + connection.CounterpartyNid + `","_connection":"` + connectionAddress + `"}`)
515516
ctx, err = c.executeContract(context.Background(), c.IBCAddresses[fmt.Sprintf("xcall-%s", testcase)], connection.KeyName, "setDefaultConnection", string(params))
516517
if err != nil {
517518
return nil, err
@@ -537,9 +538,47 @@ func (c *IconLocalnet) SendPacketXCall(ctx context.Context, keyName, _to string,
537538
}
538539

539540
// HasPacketReceipt returns the receipt of the packet sent to the target chain
540-
func (c *IconLocalnet) IsPacketReceived(ctx context.Context, params map[string]interface{}) bool {
541+
func (c *IconLocalnet) IsPacketReceived(ctx context.Context, params map[string]interface{}, order ibc.Order) bool {
542+
if order == ibc.Ordered {
543+
sequence := params["sequence"].(uint64) //2
544+
ctx, err := c.QueryContract(ctx, c.IBCAddresses["ibc"], chains.GetNextSequenceReceive, params)
545+
if err != nil {
546+
fmt.Printf("Error--%v\n", err)
547+
return false
548+
}
549+
response, err := formatHexNumberFromResponse(ctx.Value("query-result").([]byte))
550+
551+
if err != nil {
552+
fmt.Printf("Error--%v\n", err)
553+
return false
554+
}
555+
fmt.Printf("response[\"data\"]----%v", response)
556+
return sequence < response
557+
}
541558
ctx, _ = c.QueryContract(ctx, c.IBCAddresses["ibc"], chains.HasPacketReceipt, params)
542-
return string(ctx.Value("query-result").([]byte)) == "0x1"
559+
560+
response, err := formatHexNumberFromResponse(ctx.Value("query-result").([]byte))
561+
if err != nil {
562+
fmt.Printf("Error--%v\n", err)
563+
return false
564+
}
565+
return response == 1
566+
}
567+
568+
func formatHexNumberFromResponse(value []byte) (uint64, error) {
569+
pattern := `0x[0-9a-fA-F]+`
570+
regex := regexp.MustCompile(pattern)
571+
result := regex.FindString(string(value))
572+
if result == "" {
573+
return 0, fmt.Errorf("number not found")
574+
575+
}
576+
577+
response, err := strconv.ParseInt(result, 0, 64)
578+
if err != nil {
579+
return 0, err
580+
}
581+
return uint64(response), nil
543582
}
544583

545584
// FindTargetXCallMessage returns the request id and the data of the message sent to the target chain

test/chains/icon/params.go

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ func (c *IconLocalnet) GetQueryParam(method string, params map[string]interface{
4545
}},
4646
}
4747
break
48+
case chains.GetNextSequenceReceive:
49+
query = Query{
50+
"getNextSequenceReceive",
51+
Value{map[string]interface{}{
52+
"portId": params["port_id"],
53+
"channelId": params["channel_id"],
54+
}},
55+
}
56+
break
4857
case chains.GetClientState:
4958
query = Query{
5059
"getClientState",

test/chains/methods.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package chains
33
const (
44
//read only method
55
HasPacketReceipt = "has-packet-receipt"
6+
GetNextSequenceReceive = "get-next-sequence-receive"
67
GetClientState = "get-client-state"
78
GetNextClientSequence = "get-next-client-sequence"
89
GetConnection = "get-connection"

test/e2e/tests/xcall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (x *XCallTestSuite) testRollback(ctx context.Context, t *testing.T, chainA,
121121
res, err := chainA.XCall(ctx, chainB, interchaintest.UserAccount, dst, []byte(msg), []byte(rollback))
122122
assert.NoErrorf(t, err, "error on sending packet- %w", err)
123123
height, err := chainA.(ibc.Chain).Height(ctx)
124-
ctx, err = chainB.ExecuteCall(ctx, res.RequestID, res.Data)
124+
_, err = chainB.ExecuteCall(ctx, res.RequestID, res.Data)
125125
code, err := chainA.FindCallResponse(ctx, height, res.SerialNo)
126126
assert.NoErrorf(t, err, "no call response found %w", err)
127127
assert.Equal(t, "0", code)

0 commit comments

Comments
 (0)