Skip to content

Commit

Permalink
refactor: files and consts in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
whalelephant committed Jun 4, 2024
1 parent d15a6ef commit b53e917
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 119 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "contracts"]
path = contracts
url = https://github.com/nymlab/AVIDA.git
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
###########################
### Build contracts ###
###########################

build-contracts:

cd contracts; make build; cd ..
for file in ./contracts/artifacts/*.wasm; do \
echo "$$file"; \
mv "$$file" ./contracts_wasm/$$(basename "$$file" -aarch64.wasm).wasm; \
done
cp ./contracts/artifacts/** ./contracts_wasm/

.PHONY: build-contracts
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# AVIDA: Cheqd Node Interchaintests

This repo is created in order to test interchain tx for [`AVIDA`] contracts with the Cheqd network.
The submodule `contracts` contains the [`AVIDA`] code and `contracts_wasm` is where the built and optimised contracts are stored.

## Building contracts

```sh
make build-contracts
```

## Running tests

```sh
go test -v ./...

# Run only the e2e IBC test in avida_ibc_test.go
go test --short
```


[`AVIDA`]: https://github.com/nymlab/avida
107 changes: 41 additions & 66 deletions v2_resource_ibc_test.go → avida_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
//"os"
//"strings"
"testing"
"time"
//"unicode"

sdjwttypes "github.com/nymlab/cheqd-interchaintest/types"
interchaintest "github.com/strangelove-ventures/interchaintest/v7"
Expand All @@ -24,10 +20,6 @@ import (
)

func TestCheqdV2AvidaIbc(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
}

t.Parallel()

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
Expand All @@ -52,12 +44,6 @@ func TestCheqdV2AvidaIbc(t *testing.T) {
client, network := interchaintest.DockerSetup(t)
cheqd, juno := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain)

const (
ssiPath = "ssi-cheqd-juno-path"
path = "cheqd-juno-path"
relayerName = "relayer"
)

// Get a relayer instance
rf := interchaintest.NewBuiltinRelayerFactory(
ibc.CosmosRly,
Expand Down Expand Up @@ -97,18 +83,34 @@ func TestCheqdV2AvidaIbc(t *testing.T) {
_ = ic.Close()
})

const userFunds = int64(10_000_000_000_000)
junoUsers := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, juno)
junoUser := junoUsers[0]
junoNode := juno.FullNodes[0]

// ===================================
// cheqd user create resource
// ===================================
cheqdUsers := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, cheqd)
cheqdUser := cheqdUsers[0]
CreateAndUploadDid(
t,
ctx,
"did_payload.json",
"resource_payload_no_data.json",
"jwk.json",
cheqd,
cheqdUser,
collectionId,
resourceId,
)

// ===================================
// juno user upload and instantiate sdjwt contract
// ===================================
codeId, err := juno.StoreContract(
ctx,
junoUser.KeyName(),
"contracts/avida_sdjwt_verifier-aarch64.wasm",
contractPath,
)
require.NoError(t, err, "code store err")

Expand Down Expand Up @@ -141,9 +143,9 @@ func TestCheqdV2AvidaIbc(t *testing.T) {
)
require.NoError(t, err, "instantiate err")

// ===================================
// ======================================
// Add channel and make relayer relay it
// ===================================
// ======================================

createChannelOptions := ibc.CreateChannelOptions{
SourcePortName: "cheqdresource",
Expand Down Expand Up @@ -172,35 +174,17 @@ func TestCheqdV2AvidaIbc(t *testing.T) {

// Ensure channels are created successfully
channelsCheqd, err := r.GetChannels(ctx, rep.RelayerExecReporter(t), "cheqd-mainnet-1")

fmt.Println("!!!!channelsCheqd: ", channelsCheqd)
require.Len(t, channelsCheqd, 2)

testutil.WaitForBlocks(ctx, 3, juno)

// ===================================
// cheqd user create resource
// ===================================
cheqdUsers := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, cheqd)
cheqdUser := cheqdUsers[0]
CreateAndUploadDid(
t,
ctx,
"did_payload.json",
"resource_payload_no_data.json",
"jwk.json",
cheqd,
cheqdUser,
"5rjaLzcffhGUH4nt4fyfAg",
"9fbb1b86-91f8-4942-97b9-725b7714131c",
)
err = testutil.WaitForBlocks(ctx, 5, juno, cheqd)
require.NoError(t, err, "wait for blocks err")

// ============================================================
// Register route on contract with cheqd as trust registry
// ============================================================
ResourceReq := resourcetypes.ResourceReqPacket{
CollectionId: "5rjaLzcffhGUH4nt4fyfAg",
ResourceId: "9fbb1b86-91f8-4942-97b9-725b7714131c",
CollectionId: collectionId,
ResourceId: resourceId,
}
resourceReqBytes, err := json.Marshal(ResourceReq)

Expand Down Expand Up @@ -230,48 +214,39 @@ func TestCheqdV2AvidaIbc(t *testing.T) {
)
require.NoError(t, err, "exec err")

height, err := juno.Height(ctx)
require.NoError(t, err, "error fetching height before flush")

timeoutCtx, timeoutCtxCancel := context.WithTimeout(ctx, time.Second*12)
defer timeoutCtxCancel()
_ = testutil.WaitForBlocks(timeoutCtx, int(height)+3, juno)
err = testutil.WaitForBlocks(ctx, 5, juno, cheqd)
require.NoError(t, err, "wait for blocks err")

for _, channel := range channelsCheqd {
// we do not check if flushing has error because channels can be for different paths
r.Flush(ctx, rep.RelayerExecReporter(t), ssiPath, channel.ChannelID)
}

// ===========================================
// Query contract for verification key on cheqd
// ===========================================
err = testutil.WaitForBlocks(ctx, 10, juno, cheqd)
require.NoError(t, err, "wait for blocks err")

for _, channel := range channelsCheqd {
r.Flush(ctx, rep.RelayerExecReporter(t), ssiPath, channel.ChannelID)
}

// =================================================
// Query contract for verification key
// This is retrieved from IBC tx on cheqe x/resource
// =================================================
query, err := json.Marshal(sdjwttypes.QueryMsg{
GetRouteVerificationKey: &sdjwttypes.GetRouteVerificationKey{
AppAddr: sdjwttypes.TestAppAddr2,
RouteID: 1,
},
})

testutil.WaitForBlocks(ctx, 3, cheqd)
testutil.WaitForBlocks(ctx, 3, juno)

var queryData sdjwttypes.GetRouteVerificationKeyRes
err = junoNode.QueryContract(ctx, contractAddr, string(query), &queryData)

fmt.Println("!!!queryData: ", queryData)

//resourceFromContract := strings.TrimFunc(
// string(queryData.Data.GetResource().GetData()),
// func(r rune) bool {
// return !unicode.IsLetter(r) && !unicode.IsNumber(r)
// },
//)
var originalJwk sdjwttypes.OkpJwk
var returnedJwk sdjwttypes.OkpJwk

//content, err := os.ReadFile(fmt.Sprintf("%s/%s", "artifacts", "revocationList"))
//originalResource := strings.TrimFunc(string(content), func(r rune) bool {
// return !unicode.IsLetter(r) && !unicode.IsNumber(r)
//})
err = json.Unmarshal(jwk, &originalJwk)
err = json.Unmarshal([]byte(queryData.Data), &returnedJwk)

//require.Equal(t, resourceFromContract, originalResource)
require.Equal(t, originalJwk, returnedJwk)
}
3 changes: 0 additions & 3 deletions cheqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
"github.com/strangelove-ventures/interchaintest/v7/ibc"
)

const TestResourceId = "9fbb1b86-91f8-4942-97b9-725b7714131c"
const TestCollectionId = "5rjaLzcffhGUH4nt4fyfAg"

func MustUploadPayload(
ctx context.Context,
filepath string,
Expand Down
13 changes: 3 additions & 10 deletions chain_start_add_resource_test.go → cheqd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ package cheqd_interchaintest

import (
"context"
"fmt"
"testing"

interchaintest "github.com/strangelove-ventures/interchaintest/v7"
"github.com/stretchr/testify/require"
)

func TestCheqdV2StartAndUploadResource(t *testing.T) {

func TestCheqdV2UploadResource(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
}

t.Parallel()

ctx, cancelFn := context.WithCancel(context.Background())
Expand All @@ -30,17 +27,13 @@ func TestCheqdV2StartAndUploadResource(t *testing.T) {
ctx,
validatorsCount,
fullnodeCount,
//"sha-fdf3b2cb9bef2ee518f46e299eee97b4c4082ff2",
)
require.NotNil(t, ic)
require.NotNil(t, cheqd)

const userFunds = int64(10_000_000_000_000)
cheqdUsers := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, cheqd)
cheqdUser := cheqdUsers[0]

fmt.Println("cheqdUser: ", cheqdUser)

CreateAndUploadDid(
t,
ctx,
Expand All @@ -49,8 +42,8 @@ func TestCheqdV2StartAndUploadResource(t *testing.T) {
"jwk.json",
cheqd,
cheqdUser,
"5rjaLzcffhGUH4nt4fyfAg",
"9fbb1b86-91f8-4942-97b9-725b7714131c",
collectionId,
resourceId,
)

t.Cleanup(func() {
Expand Down
18 changes: 0 additions & 18 deletions contract.go

This file was deleted.

1 change: 1 addition & 0 deletions contracts
Submodule contracts added at 017cca
1 change: 0 additions & 1 deletion contracts/checksums.txt

This file was deleted.

1 change: 0 additions & 1 deletion contracts/checksums_intermediate.txt

This file was deleted.

Binary file removed contracts/vectis_anoncreds_verifier.wasm
Binary file not shown.
File renamed without changes.
1 change: 1 addition & 0 deletions contracts_wasm/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2b2b15f3d4cea85a50b8bda772ad6be2328924b667e14eb0165aa1f5fd41b195 avida_sdjwt_verifier-aarch64.wasm
29 changes: 19 additions & 10 deletions juno_start_test.go → juno_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ package cheqd_interchaintest

import (
"context"
_ "embed"
"encoding/json"
"fmt"
"testing"

sdjwttypes "github.com/nymlab/cheqd-interchaintest/types"
interchaintest "github.com/strangelove-ventures/interchaintest/v7"
"github.com/stretchr/testify/require"
)

//go:embed jwk.json
var jwk []byte

func TestJunoStart(t *testing.T) {

if testing.Short() {
t.Skip("skipping in short mode")
}
Expand All @@ -40,19 +34,16 @@ func TestJunoStart(t *testing.T) {
require.NotNil(t, ic)
require.NotNil(t, juno)

const userFunds = int64(10_000_000_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, juno)
user := users[0]

fmt.Println("user: ", user)

// ===================================
// juno user upload and instantiate sdjwt contract
// ===================================
codeId, err := juno.StoreContract(
ctx,
user.KeyName(),
"contracts/avida_sdjwt_verifier-aarch64.wasm",
contractPath,
)
require.NoError(t, err, "code store err")

Expand Down Expand Up @@ -130,6 +121,24 @@ func TestJunoStart(t *testing.T) {
require.Len(t, queryData.Data, 1, "route length mismatch")
require.Equal(t, uint64(0x1), queryData.Data[0], "RouteId mismatch")

queryKey, err := json.Marshal(sdjwttypes.QueryMsg{
GetRouteVerificationKey: &sdjwttypes.GetRouteVerificationKey{
AppAddr: sdjwttypes.TestAppAddr2,
RouteID: 1,
},
})

var queryKeyData sdjwttypes.GetRouteVerificationKeyRes
err = junoNode.QueryContract(ctx, contractAddr, string(queryKey), &queryKeyData)

var originalJwk sdjwttypes.OkpJwk
var returnedJwk sdjwttypes.OkpJwk

err = json.Unmarshal(jwk, &originalJwk)
err = json.Unmarshal([]byte(queryKeyData.Data), &returnedJwk)

require.Equal(t, originalJwk, returnedJwk)

t.Cleanup(func() {
cancelFn()
})
Expand Down
6 changes: 0 additions & 6 deletions jwk.json

This file was deleted.

Loading

0 comments on commit b53e917

Please sign in to comment.