Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
env:
GOPRIVATE: github.com/loredanacirstea*
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
KAYROS_BASE_URL: ${{ secrets.KAYROS_BASE_URL }}
KAYROS_API_KEY: ${{ secrets.KAYROS_API_KEY }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -61,3 +63,9 @@ jobs:
go test -failfast=false -timeout 2000s -v ./tests/vmhttp -wasm-runtime=wazero
go test -failfast=false -timeout 2000s -v ./tests/vmemail -wasm-runtime=wazero
# go test -failfast=false -timeout 2000s -v ./tests/vmpostgresql -wasm-runtime=wazero

if [ -n "${KAYROS_BASE_URL}" ]; then
go test -failfast=false -timeout 3000s -v -run KeeperTestSuite/TestWasmxSimpleStorage ./tests/wasmx -wasm-runtime=wazero -kayros_user_key="${KAYROS_API_KEY}" -kayros_base_url="${KAYROS_BASE_URL}" -consensus-label=consensus_kayrosp2p_ondemand_0.0.1
else
echo "Skipping Kayros test (KAYROS_BASE_URL not set)"
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ event.json
private.md
.claude/
tests/codes_compiled/
private
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ TINYGO_TARGETS := \
wasmx-fsm:28.finite_state_machine.wasm \
wasmx-raft-lib:2a.raft_library.wasm \
wasmx-raftp2p-lib:36.raftp2p_library.wasm \
wasmx-ondemand-single-lib:65.wasmx_ondemand_single_library.wasm
wasmx-ondemand-single-lib:65.wasmx_ondemand_single_library.wasm \
wasmx-kayrosp2p-lib:71.kayrosp2p_library.wasm \
wasmx-kayrosp2p-ondemand-lib:72.kayrosp2p_ondemand_library.wasm \
wasmx-kayros-verifier:75.kayros_verifier_0.0.1.wasm

# wasmx-gov:35.gov_0.0.1.wasm \
# wasmx-gov-continuous:37.gov_cont_0.0.1.wasm \
Expand Down Expand Up @@ -72,7 +75,7 @@ $(TINYGO_MODULES):
if [ -z "$$out" ]; then echo "Unknown TinyGo module: $$mod"; exit 1; fi; \
if [ ! -f "$(TINYGO_DIR)/$$mod/cmd/main.go" ]; then echo "No cmd/main.go in $$mod"; exit 1; fi; \
echo "Tidying $$mod..."; \
(cd "$(TINYGO_DIR)/$$mod" && env GOWORK=off go mod tidy) 2>/dev/null; \
(cd "$(TINYGO_DIR)/$$mod" && env GOWORK=off go mod tidy); \
echo "Building $$mod -> $(PRECOMPILE_DIR)/$$out"; \
(cd "$(TINYGO_DIR)/$$mod" && env GOWORK=off tinygo build -o "$(abspath $(PRECOMPILE_DIR))/$$out" -no-debug -scheduler=none -gc=leaking -target=wasi ./cmd) 2>/dev/null; \
(cd "$(TINYGO_DIR)/$$mod" && env GOWORK=off tinygo build -o "$(abspath $(PRECOMPILE_DIR))/$$out" -no-debug -scheduler=none -gc=leaking -target=wasi ./cmd); \
echo "Built $(PRECOMPILE_DIR)/$$out"
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use (
./tests/testdata/tinygo/wasmx-gov
./tests/testdata/tinygo/wasmx-gov-continuous
./tests/testdata/tinygo/wasmx-multichain-registry
./tests/testdata/tinygo/wasmx-kayros-verifier
// tests
./tests/testdata/tinygo/emailchain
./tests/testdata/tinygo/add
Expand Down
3 changes: 3 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ go test --count=1 -timeout 300s -v -run KeeperTestSuite/TestEwasmFibonacci ./x/w

go test --count=1 -timeout 3000s -v -run TestKeeperTestSuite/TestWasmxSimpleStorage ./tests/wasmx -benchmark=true -wasm-runtime=wazero

go test --count=1 -timeout 3000s -v -run TestKeeperTestSuite/TestWasmxSimpleStorage ./tests/wasmx -wasm-runtime=wazero -consensus-label=consensus_kayrosp2p_ondemand_0.0.1 -kayros_user_key=0x0000000000000000000000000000000000000000000000000000000000000001 -kayros_base_url=https://kayros_indexer_url


```
* for wasmedge
```bash
Expand Down
87 changes: 87 additions & 0 deletions tests/kayros/keeper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package keeper_test

import (
"flag"
"os"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/stretchr/testify/suite"

//nolint

wt "github.com/loredanacirstea/wasmx/testutil/wasmx"

wazero "github.com/loredanacirstea/wasmx-wazero"

ut "github.com/loredanacirstea/mythos-tests/utils"
)

var (
wasmRuntime string
runKnownFixme bool
)

// TestMain is the main entry point for the tests.
func TestMain(m *testing.M) {
flag.StringVar(&wasmRuntime, "wasm-runtime", "default", "Set the wasm runtime (e.g. wasmedge, wazero)")
flag.BoolVar(&runKnownFixme, "run-fixme", false, "Run skipped fixme tests")

// Parse the flags. Only flags after `--` in `go test` command line will be passed here.
flag.Parse()

os.Exit(m.Run())
}

// KeeperTestSuite is a testing suite to test keeper functions
type KeeperTestSuite struct {
wt.KeeperTestSuite
}

var s *KeeperTestSuite

func (suite *KeeperTestSuite) SetupSuite() {
suite.MaxBlockGas = 100_000_000_000
suite.SystemContractsModify = ut.SystemContractsModify(wasmRuntime)
mydir, err := os.Getwd()
if err != nil {
panic(err)
}

switch wasmRuntime {
case "wasmedge":
// suite.WasmVmMeta = wasmedge.WasmEdgeVmMeta{}
// suite.CompiledCacheDir = ut.GetCompiledCacheDir(mydir, "wasmedge")
panic("wasmedge not activated")
default:
// default runtime
suite.WasmVmMeta = wazero.NewWazeroVmMeta()
suite.CompiledCacheDir = ut.GetCompiledCacheDir(mydir, "wazero")
}

suite.SetupChains()
}

// TestKeeperTestSuite runs all the tests within this package.
func TestKeeperTestSuite(t *testing.T) {
s = new(KeeperTestSuite)
suite.Run(t, s)

// Run Ginkgo integration tests
RegisterFailHandler(Fail)
RunSpecs(t, "Keeper Suite")
}

func SkipFixmeTests(t *testing.T, name string) {
if !runKnownFixme {
t.Skipf("TODO: fixme %s", name)
}
}

type VerifyProofRequest struct {
Data string `json:"data"` // base64
DataType string `json:"data_type"` // hex
HashAlgo string `json:"hash_algo"`
}
165 changes: 165 additions & 0 deletions tests/kayros/verifier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package keeper_test

import (
"encoding/base64"
"encoding/hex"
"encoding/json"

"github.com/loredanacirstea/wasmx/x/wasmx/types"
)

func (suite *KeeperTestSuite) TestKayrosVerifier() {
appA := s.AppContext()
verifierAddr, err := appA.App.WasmxKeeper.GetAddressOrRole(appA.Context(), types.ROLE_VERIFIER)
suite.Require().NoError(err)

sender := suite.GetRandomAccount()

apiBaseUrl := ""
apiUserKey := ""
if suite.StartNodeEnv != nil {
apiBaseUrl = suite.StartNodeEnv["kayros_base_url"]
apiUserKey = suite.StartNodeEnv["kayros_user_key"]
}

if apiBaseUrl == "" || apiUserKey == "" {
suite.T().Skip("SKIPPING ... set kayros_base_url and kayros_user_key for TestKayrosVerifier")
}

for _, pair := range KAYROS_TEST_BY_DATA {
dataTypeHex := pair[0]
dataHashHex := pair[1]
dataType, err := hex.DecodeString(dataTypeHex)
suite.Require().NoError(err)
dataHash, err := hex.DecodeString(dataHashHex)
suite.Require().NoError(err)

verifyProofHashReq := map[string]any{
"verify_proof_hash": map[string]any{
"data_type": dataType,
"data_hash": dataHash,
"api_base_url": apiBaseUrl,
"api_user_key": apiUserKey,
},
}
msg, err := json.Marshal(verifyProofHashReq)
suite.Require().NoError(err)
res := appA.WasmxQueryRaw(sender, verifierAddr, types.WasmxExecutionMessage{Data: msg}, nil, nil)

var verifyResp struct {
Ok bool `json:"ok"`
Error string `json:"error"`
}
suite.Require().NoError(json.Unmarshal(res, &verifyResp))
suite.Require().True(verifyResp.Ok, verifyResp.Error)

if KAYROS_TOPLEVEL_HASH != "" {
verifyProofHashReq = map[string]any{
"verify_proof_hash_with_inclusion": map[string]any{
"data_type": dataType,
"data_hash": dataHash,
"hash_algo": "sha256",
"trusted_root_hash": KAYROS_TOPLEVEL_HASH,
"trusted_level": KAYROS_TOPLEVEL_LEVEL,
"trusted_position": KAYROS_TOPLEVEL_POSITION,
"api_base_url": apiBaseUrl,
"api_user_key": apiUserKey,
},
}
msg, err = json.Marshal(verifyProofHashReq)
suite.Require().NoError(err)
res = appA.WasmxQueryRaw(sender, verifierAddr, types.WasmxExecutionMessage{Data: msg}, nil, nil)

verifyResp = struct {
Ok bool `json:"ok"`
Error string `json:"error"`
}{}
suite.Require().NoError(json.Unmarshal(res, &verifyResp))
suite.Require().True(verifyResp.Ok, verifyResp.Error)
}
}

for _, proof := range KAYROS_TEST_PROOFS {
dataType, err := hex.DecodeString(proof.DataType)
suite.Require().NoError(err)
data, err := base64.StdEncoding.DecodeString(proof.Data)
suite.Require().NoError(err)

verifyProofReq := map[string]any{
"verify_proof": map[string]any{
"data": data,
"data_type": dataType,
"hash_algo": proof.HashAlgo,
"api_base_url": apiBaseUrl,
"api_user_key": apiUserKey,
},
}
msg, err := json.Marshal(verifyProofReq)
suite.Require().NoError(err)
res := appA.WasmxQueryRaw(sender, verifierAddr, types.WasmxExecutionMessage{Data: msg}, nil, nil)

var verifyResp struct {
Ok bool `json:"ok"`
Error string `json:"error"`
}
suite.Require().NoError(json.Unmarshal(res, &verifyResp))
suite.Require().True(verifyResp.Ok, verifyResp.Error)

if KAYROS_TOPLEVEL_HASH != "" {
verifyProofReq = map[string]any{
"verify_proof_with_inclusion": map[string]any{
"data": data,
"data_type": dataType,
"hash_algo": proof.HashAlgo,
"trusted_root_hash": KAYROS_TOPLEVEL_HASH,
"trusted_level": KAYROS_TOPLEVEL_LEVEL,
"trusted_position": KAYROS_TOPLEVEL_POSITION,
"api_base_url": apiBaseUrl,
"api_user_key": apiUserKey,
},
}
msg, err = json.Marshal(verifyProofReq)
suite.Require().NoError(err)
res = appA.WasmxQueryRaw(sender, verifierAddr, types.WasmxExecutionMessage{Data: msg}, nil, nil)

verifyResp = struct {
Ok bool `json:"ok"`
Error string `json:"error"`
}{}
suite.Require().NoError(json.Unmarshal(res, &verifyResp))
suite.Require().True(verifyResp.Ok, verifyResp.Error)
}
}
}

var KAYROS_TEST_BY_HASH = []string{
"c883af9b3ffc8261f6385e33dcd0bc825de1480dad4b5e9c9425c45c66655065",
"b605d60a6a531c57eba104a0e28a8be111e95d7a88a257066274de688eec1216",
}

var KAYROS_TEST_BY_DATA = [][]string{
{
"7761736d785f6d7974686f735f373030312d315f313736373039353338333930",
"374f1b87a48721c2a3f4d0777a6848e23edb13d0209a69f65330ee7ae84d5e9c",
},
}

// var KAYROS_TOPLEVEL_HASH = "be475ef98de5dcba176730b044a32239dbe5e8bb4f2172d5d8c555907eb445e0"
// var KAYROS_TOPLEVEL_LEVEL = 1
// var KAYROS_TOPLEVEL_POSITION = 10

var KAYROS_TOPLEVEL_HASH = ""
var KAYROS_TOPLEVEL_LEVEL = -1
var KAYROS_TOPLEVEL_POSITION = -1

var KAYROS_TEST_PROOFS = []VerifyProofRequest{
{
Data: "CsoBCscBCiMvbXl0aG9zLndhc214LnYxLk1zZ0V4ZWN1dGVDb250cmFjdBKfAQotbXl0aG9zMTdzY2NsMDk1MzJod2g5eTRzeTlxNXNsd216ajdrZnBhNDJ5czY2Ei1teXRob3MxN2syMGVxanJ0czNlaDZteGtxcXNraHp2NGtqYWUwNTNrYzhkbGQaP3siZGF0YSI6ImV5SnpaWFFpT25zaWEyVjVJam9pYUdWc2JHOGlMQ0oyWVd4MVpTSTZJbk5oYlcxNUluMTkifRJvClAKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECqkwoU7+JW3gfOgr6as2ZJZD6Vo2Ob7H8sgOIIUOIrasSBAoCCAEYAxIbChMKBGFteXQSCzEwMDAwMDAwMDAwEICU69wDGkAMfcSxXine4wbRzIm1edq7DzGF089DRVHmeVI159CfqlcIS8adRZVD5ndJ4fFpUfkOjsg5DhLmQvyP+QGTynI0",
DataType: "7761736d785f74785f6d7974686f735f373030312d315f313736383834393037",
HashAlgo: "sha256",
// txhash
// 9bfbd26d8e9cc4f69eca1ffadc2e5db2891e0781efad9ec969e0cf980208eb10
// kayros hash
// 5dbff8d307b6576610edea33ef2df6e53c93d9849b76f98b2665f59305d8dd14
},
}
4 changes: 4 additions & 0 deletions tests/testdata/tinygo/emailchain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
//export wasmx_nondeterministic_1
func Wasmx_nondeterministic_1() {}

//go:wasm-module httpclient
//export wasmx_httpclient_i64_1
func Wasmx_httpclient_i64_1() {}

//go:wasm-module wasmx
//export memory_ptrlen_i64_1
func Wemory_ptrlen_i64_1() {}
Expand Down
4 changes: 0 additions & 4 deletions tests/testdata/tinygo/wasmx-env-httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
utils "github.com/loredanacirstea/wasmx-env-utils"
)

//go:wasm-module httpclient
//export wasmx_httpclient_i64_1
func wasmx_httpclient_i64_1() {}

//go:wasmimport httpclient Request
func Request_(reqPtr int64) int64

Expand Down
6 changes: 5 additions & 1 deletion tests/testdata/tinygo/wasmx-env/lib/wasmx_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func StorageStore(key, value []byte) {
Log([]byte("storagestore"), [][32]byte{})
StorageStore_(utils.BytesToPackedPtr(key), utils.BytesToPackedPtr(value))
}

Expand Down Expand Up @@ -331,6 +330,11 @@ func Sha256(data []byte) []byte {
return out
}

func Keccak256(data []byte) []byte {
out := utils.PackedPtrToBytes(Keccak256_(utils.BytesToPackedPtr(data)))
return out
}

func MerkleHash(slices []string) []byte {
payload := struct {
Slices []string `json:"slices"`
Expand Down
Loading
Loading