diff --git a/e2e/api_test.go b/e2e/api_test.go index 2cbddd0f1..805ddd705 100644 --- a/e2e/api_test.go +++ b/e2e/api_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/crypto/keys" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/mesg-foundation/engine/app" "github.com/mesg-foundation/engine/config" @@ -31,9 +32,10 @@ type apiclient struct { } var ( - client apiclient - cclient *cosmos.Client - cdc = app.MakeCodec() + minExecutionPrice sdk.Coins + client apiclient + cclient *cosmos.Client + cdc = app.MakeCodec() ) const ( @@ -77,6 +79,9 @@ func TestAPI(t *testing.T) { cfg, err := config.New() require.NoError(t, err) + minExecutionPrice, err = sdk.ParseCoins(cfg.DefaultExecutionPrice) + require.NoError(t, err) + cosmos.CustomizeConfig(cfg) conn, err := grpc.DialContext(context.Background(), "localhost:50052", grpc.WithInsecure()) diff --git a/e2e/orchestrator_event_task_test.go b/e2e/orchestrator_event_task_test.go index 2b5246004..619800ceb 100644 --- a/e2e/orchestrator_event_task_test.go +++ b/e2e/orchestrator_event_task_test.go @@ -5,12 +5,15 @@ import ( "testing" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/protobuf/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) func testOrchestratorEventTask(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { @@ -47,6 +50,16 @@ func testOrchestratorEventTask(executionStream pb.Execution_StreamClient, instan require.NoError(t, err) processHash = respProc.Hash }) + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) + t.Run("trigger process", func(t *testing.T) { _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ InstanceHash: instanceHash, diff --git a/e2e/orchestrator_filter_test.go b/e2e/orchestrator_filter_test.go index f89b2dc07..0a7c75e77 100644 --- a/e2e/orchestrator_filter_test.go +++ b/e2e/orchestrator_filter_test.go @@ -6,12 +6,15 @@ import ( "testing" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/protobuf/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) func testOrchestratorFilter(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { @@ -63,6 +66,16 @@ func testOrchestratorFilter(executionStream pb.Execution_StreamClient, instanceH require.NoError(t, err) processHash = respProc.Hash }) + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) + t.Run("pass filter", func(t *testing.T) { t.Run("trigger process", func(t *testing.T) { _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ diff --git a/e2e/orchestrator_map_const_test.go b/e2e/orchestrator_map_const_test.go index cf9c73ebc..7d761cc1d 100644 --- a/e2e/orchestrator_map_const_test.go +++ b/e2e/orchestrator_map_const_test.go @@ -5,12 +5,15 @@ import ( "testing" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/protobuf/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) func testOrchestratorMapConst(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { @@ -62,6 +65,16 @@ func testOrchestratorMapConst(executionStream pb.Execution_StreamClient, instanc require.NoError(t, err) processHash = respProc.Hash }) + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) + t.Run("trigger process", func(t *testing.T) { _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ InstanceHash: instanceHash, diff --git a/e2e/orchestrator_nested_data_test.go b/e2e/orchestrator_nested_data_test.go index 062a86d6d..2ef365966 100644 --- a/e2e/orchestrator_nested_data_test.go +++ b/e2e/orchestrator_nested_data_test.go @@ -5,12 +5,15 @@ import ( "testing" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/protobuf/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) func testOrchestratorNestedData(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { @@ -78,6 +81,16 @@ func testOrchestratorNestedData(executionStream pb.Execution_StreamClient, insta }, }, } + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) + t.Run("trigger process", func(t *testing.T) { _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ InstanceHash: instanceHash, diff --git a/e2e/orchestrator_nested_map_test.go b/e2e/orchestrator_nested_map_test.go index 34239c3fe..f8dd257ec 100644 --- a/e2e/orchestrator_nested_map_test.go +++ b/e2e/orchestrator_nested_map_test.go @@ -4,12 +4,15 @@ import ( "context" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/protobuf/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) func testOrchestratorNestedMap(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { @@ -105,6 +108,16 @@ func testOrchestratorNestedMap(executionStream pb.Execution_StreamClient, instan require.NoError(t, err) processHash = respProc.Hash }) + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) + t.Run("trigger process", func(t *testing.T) { _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ InstanceHash: instanceHash, diff --git a/e2e/orchestrator_ref_grand_parent_task_test.go b/e2e/orchestrator_ref_grand_parent_task_test.go index 861f0af05..e6924c1e1 100644 --- a/e2e/orchestrator_ref_grand_parent_task_test.go +++ b/e2e/orchestrator_ref_grand_parent_task_test.go @@ -5,12 +5,15 @@ import ( "testing" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/protobuf/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) func testOrchestratorRefGrandParentTask(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { @@ -103,6 +106,19 @@ func testOrchestratorRefGrandParentTask(executionStream pb.Execution_StreamClien require.NoError(t, err) processHash = respProc.Hash }) + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) t.Run("trigger process", func(t *testing.T) { _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ InstanceHash: instanceHash, diff --git a/e2e/orchestrator_ref_path_nested_test.go b/e2e/orchestrator_ref_path_nested_test.go index 1b5d8bad9..4e15db361 100644 --- a/e2e/orchestrator_ref_path_nested_test.go +++ b/e2e/orchestrator_ref_path_nested_test.go @@ -5,12 +5,15 @@ import ( "testing" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/protobuf/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) func testOrchestratorRefPathNested(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { @@ -224,6 +227,17 @@ func testOrchestratorRefPathNested(executionStream pb.Execution_StreamClient, in }, }, } + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) t.Run("trigger process", func(t *testing.T) { _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ InstanceHash: instanceHash, diff --git a/e2e/orchestrator_result_task_test.go b/e2e/orchestrator_result_task_test.go index 65eb4b06c..0a74b8fa9 100644 --- a/e2e/orchestrator_result_task_test.go +++ b/e2e/orchestrator_result_task_test.go @@ -4,12 +4,15 @@ import ( "context" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/protobuf/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) func testOrchestratorResultTask(executionStream pb.Execution_StreamClient, runnerHash hash.Hash, instanceHash hash.Hash) func(t *testing.T) { @@ -46,6 +49,17 @@ func testOrchestratorResultTask(executionStream pb.Execution_StreamClient, runne require.NoError(t, err) processHash = respProc.Hash }) + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) t.Run("trigger process", func(t *testing.T) { _, err := client.ExecutionClient.Create(context.Background(), &pb.CreateExecutionRequest{ TaskKey: "task1", diff --git a/e2e/orchestrator_test.go b/e2e/orchestrator_test.go index 0c8c95010..77de52ece 100644 --- a/e2e/orchestrator_test.go +++ b/e2e/orchestrator_test.go @@ -15,6 +15,7 @@ func testOrchestrator(t *testing.T) { acknowledgement.WaitForStreamToBeReady(executionStream) // running orchestrator tests + t.Run("withdraw from process", testOrchestratorProcessWithdraw(executionStream, testInstanceHash)) t.Run("event task", testOrchestratorEventTask(executionStream, testInstanceHash)) t.Run("result task", testOrchestratorResultTask(executionStream, testRunnerHash, testInstanceHash)) t.Run("map const", testOrchestratorMapConst(executionStream, testInstanceHash)) diff --git a/e2e/orchestrator_withdraw_test.go b/e2e/orchestrator_withdraw_test.go new file mode 100644 index 000000000..37619024b --- /dev/null +++ b/e2e/orchestrator_withdraw_test.go @@ -0,0 +1,107 @@ +package main + +import ( + "context" + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/mesg-foundation/engine/execution" + "github.com/mesg-foundation/engine/hash" + "github.com/mesg-foundation/engine/process" + pb "github.com/mesg-foundation/engine/protobuf/api" + "github.com/mesg-foundation/engine/protobuf/types" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" +) + +func testOrchestratorProcessWithdraw(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { + return func(t *testing.T) { + var processHash hash.Hash + + t.Run("create process", func(t *testing.T) { + respProc, err := client.ProcessClient.Create(context.Background(), &pb.CreateProcessRequest{ + Name: "event-task-process", + Nodes: []*process.Process_Node{ + { + Key: "n0", + Type: &process.Process_Node_Event_{ + Event: &process.Process_Node_Event{ + InstanceHash: instanceHash, + EventKey: "test_event", + }, + }, + }, + { + Key: "n1", + Type: &process.Process_Node_Task_{ + Task: &process.Process_Node_Task{ + InstanceHash: instanceHash, + TaskKey: "task1", + }, + }, + }, + }, + Edges: []*process.Process_Edge{ + {Src: "n0", Dst: "n1"}, + }, + }) + require.NoError(t, err) + processHash = respProc.Hash + }) + t.Run("send coins to process", func(t *testing.T) { + acc, err := cclient.GetAccount() + require.NoError(t, err) + + to := sdk.AccAddress(crypto.AddressHash(processHash)) + msg := bank.NewMsgSend(acc.GetAddress(), to, minExecutionPrice) + _, err = cclient.BuildAndBroadcastMsg(msg) + require.NoError(t, err) + }) + + t.Run("trigger process", func(t *testing.T) { + _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ + InstanceHash: instanceHash, + Key: "test_event", + Data: &types.Struct{ + Fields: map[string]*types.Value{ + "msg": { + Kind: &types.Value_StringValue{ + StringValue: "foo_1", + }, + }, + "timestamp": { + Kind: &types.Value_NumberValue{ + NumberValue: float64(time.Now().Unix()), + }, + }, + }, + }, + }) + require.NoError(t, err) + }) + t.Run("check in progress execution", func(t *testing.T) { + exec, err := executionStream.Recv() + require.NoError(t, err) + require.True(t, processHash.Equal(exec.ProcessHash)) + require.Equal(t, execution.Status_InProgress, exec.Status) + }) + t.Run("check completed execution", func(t *testing.T) { + exec, err := executionStream.Recv() + require.NoError(t, err) + require.True(t, processHash.Equal(exec.ProcessHash)) + require.Equal(t, execution.Status_Completed, exec.Status) + }) + t.Run("check coins on process", func(t *testing.T) { + var coins sdk.Coins + param := bank.NewQueryBalanceParams(sdk.AccAddress(crypto.AddressHash(processHash))) + require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins)) + require.True(t, coins.IsZero()) + }) + t.Run("delete process", func(t *testing.T) { + _, err := client.ProcessClient.Delete(context.Background(), &pb.DeleteProcessRequest{Hash: processHash}) + require.NoError(t, err) + }) + } +}