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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ PRECOMPILE_DIR := ./wasmx/x/wasmx/vm/precompiles
TINYGO_TARGETS := \
wasmx-fsm:28.finite_state_machine.wasm \
wasmx-raft-lib:2a.raft_library.wasm \
wasmx-raftp2p-lib:36.raftp2p_library.wasm
wasmx-raftp2p-lib:36.raftp2p_library.wasm \
wasmx-ondemand-single-lib:65.wasmx_ondemand_single_library.wasm

# wasmx-gov:35.gov_0.0.1.wasm \
# wasmx-gov-continuous:37.gov_cont_0.0.1.wasm \
Expand Down
112 changes: 112 additions & 0 deletions tests/testdata/tinygo/wasmx-ondemand-single-lib/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package main

import (
"encoding/json"

wasmx "github.com/loredanacirstea/wasmx-env/lib"
fsm "github.com/loredanacirstea/wasmx-fsm/lib"
lib "github.com/loredanacirstea/wasmx-ondemand-single-lib/lib"
raft "github.com/loredanacirstea/wasmx-raft-lib/lib"
raftp2p "github.com/loredanacirstea/wasmx-raftp2p-lib/lib"
)

//go:wasm-module wasmx
//export memory_ptrlen_i64_1
func Memory_ptrlen_i64_1() {}

//go:wasm-module wasmx
//export wasmx_env_i64_2
func Wasmx_env_i64_2() {}

//go:wasm-module consensus
//export wasmx_consensus_json_i64_1
func Wasmx_consensus_json_i64_1() {}

//go:wasm-module wasmxcore
//export wasmx_env_core_i64_1
func Wasmx_env_core_i64_1() {}

//go:wasm-module crosschain
//export wasmx_crosschain_json_i64_1
func Wasmx_crosschain_json_i64_1() {}

//go:wasm-module multichain
//export wasmx_multichain_json_i64_1
func Wasmx_multichain_json_i64_1() {}

//go:wasm-module p2p
//export wasmx_p2p_json_i64_1
func Wasmx_p2p_json_i64_1() {}

//go:wasm-module wasmxcore
//export wasmx_nondeterministic_1
func Wasmx_nondeterministic_1() {}

//go:wasm-module wasmx-ondemand-single
//export instantiate
func Instantiate() {}

func main() {
// Only internal
wasmx.OnlyInternal(lib.MODULE_NAME, "")

databz := wasmx.GetCallData()
var calld fsm.ExternalActionCallData
if err := json.Unmarshal(databz, &calld); err != nil {
lib.Revert("invalid call data: " + err.Error() + ": " + string(databz))
return
}

// Route methods
switch calld.Method {
case "ifNewTransaction":
ok, err := raftp2p.IfNewTransaction(calld.Params, calld.Event)
if err != nil {
lib.Revert(err.Error())
return
}
res := raft.WrapGuard(ok)
wasmx.Finish(res)
return
case "addToMempool":
if err := raftp2p.AddToMempool(calld.Params, calld.Event); err != nil {
lib.Revert(err.Error())
return
}
case "setupNode":
if err := lib.SetupNode(calld.Params, calld.Event); err != nil {
lib.Revert(err.Error())
return
}
case "sendNewTransactionResponse":
if err := raft.SendNewTransactionResponse(nil, fsm.EventObject{}); err != nil {
lib.Revert(err.Error())
return
}
case "newBlock":
if err := lib.NewBlock(); err != nil {
lib.Revert(err.Error())
return
}
case "setup":
if err := raft.Setup(calld.Params, calld.Event); err != nil {
lib.Revert(err.Error())
return
}
case "StartNode":
// TODO
if err := lib.StartNode(); err != nil {
lib.Revert(err.Error())
return
}
case "rollback":
if err := raft.Rollback(calld.Params, calld.Event); err != nil {
lib.Revert("Rollback failed: " + err.Error())
return
}
default:
wasmx.Revert(append([]byte("invalid function call data: "), databz...))
return
}
wasmx.Finish(wasmx.GetFinishData())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"context":[{"key":"maxLevel","value":0},{"key":"blockTimeout","value":"blockTimeoutInternal"},{"key":"currentLevel","value":0},{"key":"membersCount","value":1},{"key":"blockTimeoutInternal","value":3000}],"id":"OnDemand-Single","initial":"uninitialized","states":[{"name":"uninitialized","after":[],"always":[],"on":[{"name":"initialize","transitions":[{"target":"#OnDemand-Single.initialized","guard":null,"actions":[],"meta":[]}]}],"entry":[],"exit":[],"initial":"","states":[]},{"name":"initialized","after":[],"always":[],"on":[],"entry":[],"exit":[],"initial":"unstarted","states":[{"name":"unstarted","after":[],"always":[],"on":[{"name":"start","transitions":[{"target":"#OnDemand-Single.initialized.started","guard":null,"actions":[{"type":"StartNode","params":[]}],"meta":[]}]},{"name":"setup","transitions":[{"target":"#OnDemand-Single.initialized.unstarted","guard":null,"actions":[{"type":"setup","params":[]}],"meta":[]}]},{"name":"prestart","transitions":[{"target":"#OnDemand-Single.initialized.prestart","guard":null,"actions":[],"meta":[]}]},{"name":"setupNode","transitions":[{"target":"#OnDemand-Single.initialized.unstarted","guard":null,"actions":[{"type":"setupNode","params":[]}],"meta":[]}]}],"entry":[],"exit":[],"initial":"","states":[]},{"name":"started","after":[],"always":[],"on":[{"name":"start","transitions":[{"target":"#OnDemand-Single.initialized.started","guard":null,"actions":[{"type":"StartNode","params":[]}],"meta":[]}]}],"entry":[],"exit":[],"initial":"active","states":[{"name":"active","after":[],"always":[],"on":[{"name":"newTransaction","transitions":[{"target":"#OnDemand-Single.initialized.started.proposer","guard":{"type":"ifNewTransaction","params":[]},"actions":[{"type":"addToMempool","params":[]},{"type":"sendNewTransactionResponse","params":[]}],"meta":[]}]}],"entry":[],"exit":[],"initial":"","states":[]},{"name":"proposer","after":[],"always":[{"name":"always","transitions":[{"target":"#OnDemand-Single.initialized.started.active","actions":[{"type":"newBlock","params":[]}],"guard":null,"meta":[]}]}],"on":[],"entry":[],"exit":[],"initial":"","states":[]}]},{"name":"prestart","after":[{"name":"500","transitions":[{"target":"#OnDemand-Single.initialized.started","guard":null,"actions":[],"meta":[]}]}],"always":[],"on":[],"entry":[],"exit":[],"initial":"","states":[]}]}]}
133 changes: 133 additions & 0 deletions tests/testdata/tinygo/wasmx-ondemand-single-lib/diagram/stately.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// @ts-nocheck

import { createMachine } from "xstate";

export const machine = createMachine({
context: {
maxLevel: 0,
blockTimeout: "blockTimeoutInternal",
currentLevel: 0,
membersCount: 1,
blockTimeoutInternal: 3000,
},
id: "OnDemand-Single",
initial: "uninitialized",
states: {
uninitialized: {
on: {
initialize: {
target: "initialized",
},
},
},
initialized: {
initial: "unstarted",
states: {
unstarted: {
on: {
start: {
target: "started",
actions: {
type: "StartNode",
},
},
setup: {
target: "unstarted",
actions: {
type: "setup",
},
},
prestart: {
target: "prestart",
},
setupNode: {
target: "unstarted",
actions: {
type: "setupNode",
},
},
},
},
started: {
initial: "active",
on: {
start: {
target: "started",
actions: {
type: "StartNode",
},
},
},
states: {
active: {
on: {
newTransaction: {
target: "proposer",
actions: [
{
type: "addToMempool",
},
{
type: "sendNewTransactionResponse",
},
],
guard: {
type: "ifNewTransaction",
},
},
},
},
proposer: {
always: {
target: "active",
actions: {
type: "newBlock",
},
},
},
},
},
prestart: {
after: {
"500": {
target: "started",
},
},
},
},
},
},
}).withConfig({
actions: {
StartNode: function (context, event) {
// Add your action code here
// ...
},
setup: function (context, event) {
// Add your action code here
// ...
},
setupNode: function (context, event) {
// Add your action code here
// ...
},
addToMempool: function (context, event) {
// Add your action code here
// ...
},
sendNewTransactionResponse: function (context, event) {
// Add your action code here
// ...
},
newBlock: function (context, event) {
// Add your action code here
// ...
},
},
guards: {
ifNewTransaction: function (context, event) {
// Add your guard condition here
return true;
},
},
});
64 changes: 64 additions & 0 deletions tests/testdata/tinygo/wasmx-ondemand-single-lib/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module github.com/loredanacirstea/wasmx-ondemand-single-lib

go 1.24

toolchain go1.24.4

require github.com/loredanacirstea/wasmx-env v0.0.0

require github.com/loredanacirstea/wasmx-fsm v0.0.0

require github.com/loredanacirstea/wasmx-env-core v0.0.0 // indirect

require github.com/loredanacirstea/wasmx-env-consensus v0.0.0 // indirect

require github.com/loredanacirstea/wasmx-env-crosschain v0.0.0 // indirect

require github.com/loredanacirstea/wasmx-staking v0.0.0 // indirect

require github.com/loredanacirstea/wasmx-consensus-utils v0.0.0 // indirect

require github.com/loredanacirstea/wasmx-blocks v0.0.0 // indirect

require github.com/loredanacirstea/wasmx-env-multichain v0.0.0 // indirect

require github.com/loredanacirstea/wasmx-raft-lib v0.0.0

require (
github.com/loredanacirstea/wasmx-env-p2p v0.0.0
github.com/loredanacirstea/wasmx-raftp2p-lib v0.0.0
)

require (
cosmossdk.io/math v1.5.3 // indirect
github.com/loredanacirstea/wasmx-env-utils v0.0.0 // indirect
github.com/loredanacirstea/wasmx-utils v0.0.0 // indirect
)

replace github.com/loredanacirstea/wasmx-env v0.0.0 => ../wasmx-env

replace github.com/loredanacirstea/wasmx-env-utils v0.0.0 => ../wasmx-env-utils

replace github.com/loredanacirstea/wasmx-utils v0.0.0 => ../wasmx-utils

replace github.com/loredanacirstea/wasmx-fsm v0.0.0 => ../wasmx-fsm

replace github.com/loredanacirstea/wasmx-env-core v0.0.0 => ../wasmx-env-core

replace github.com/loredanacirstea/wasmx-env-crosschain v0.0.0 => ../wasmx-env-crosschain

replace github.com/loredanacirstea/wasmx-env-consensus v0.0.0 => ../wasmx-env-consensus

replace github.com/loredanacirstea/wasmx-staking v0.0.0 => ../wasmx-staking

replace github.com/loredanacirstea/wasmx-consensus-utils v0.0.0 => ../wasmx-consensus-utils

replace github.com/loredanacirstea/wasmx-blocks v0.0.0 => ../wasmx-blocks

replace github.com/loredanacirstea/wasmx-env-multichain v0.0.0 => ../wasmx-env-multichain

replace github.com/loredanacirstea/wasmx-raft-lib v0.0.0 => ../wasmx-raft-lib

replace github.com/loredanacirstea/wasmx-raftp2p-lib v0.0.0 => ../wasmx-raftp2p-lib

replace github.com/loredanacirstea/wasmx-env-p2p v0.0.0 => ../wasmx-env-p2p
12 changes: 12 additions & 0 deletions tests/testdata/tinygo/wasmx-ondemand-single-lib/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cosmossdk.io/math v1.5.3 h1:WH6tu6Z3AUCeHbeOSHg2mt9rnoiUWVWaQ2t6Gkll96U=
cosmossdk.io/math v1.5.3/go.mod h1:uqcZv7vexnhMFJF+6zh9EWdm/+Ylyln34IvPnBauPCQ=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
Loading
Loading