From d9e4ce921ddea173a89c24bf5907303f49e3baa5 Mon Sep 17 00:00:00 2001 From: krhubert Date: Tue, 3 Mar 2020 11:42:28 +0100 Subject: [PATCH 1/5] Get coins from execution process if attached --- x/execution/internal/keeper/keeper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x/execution/internal/keeper/keeper.go b/x/execution/internal/keeper/keeper.go index c17453dc2..1049c2c83 100644 --- a/x/execution/internal/keeper/keeper.go +++ b/x/execution/internal/keeper/keeper.go @@ -118,8 +118,12 @@ func (k *Keeper) Create(ctx sdk.Context, msg types.MsgCreateExecution) (*executi M.InProgress.Add(1) } + from := msg.Signer + if !msg.Request.ProcessHash.IsZero() { + from = sdk.AccAddress(crypto.AddressHash(msg.Request.ProcessHash)) + } execAddress := sdk.AccAddress(crypto.AddressHash(exec.Hash)) - if err := k.bankKeeper.SendCoins(ctx, msg.Signer, execAddress, price); err != nil { + if err := k.bankKeeper.SendCoins(ctx, from, execAddress, price); err != nil { return nil, err } From 752c23b01ca95f44ab6378d7c10430c0209e6929 Mon Sep 17 00:00:00 2001 From: krhubert Date: Tue, 3 Mar 2020 16:30:37 +0100 Subject: [PATCH 2/5] Add and fix tests for processes --- e2e/api_test.go | 11 +- e2e/orchestrator_event_task_test.go | 13 +++ e2e/orchestrator_filter_test.go | 13 +++ e2e/orchestrator_map_const_test.go | 13 +++ e2e/orchestrator_nested_data_test.go | 13 +++ e2e/orchestrator_nested_map_test.go | 13 +++ ...orchestrator_ref_grand_parent_task_test.go | 16 +++ e2e/orchestrator_ref_path_nested_test.go | 14 +++ e2e/orchestrator_result_task_test.go | 14 +++ e2e/orchestrator_test.go | 1 + e2e/orchestrator_withdraw_test.go | 107 ++++++++++++++++++ 11 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 e2e/orchestrator_withdraw_test.go 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) + }) + } +} From 5137bf0a3cb1fd2b0e58dc54743c1b7e055212c4 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Fri, 13 Mar 2020 15:43:05 +0700 Subject: [PATCH 3/5] Transfer coins from the process's owner to the process on creation --- app/app.go | 2 +- config/config.go | 2 +- x/process/internal/keeper/keeper.go | 16 +++++++++++++++- x/process/internal/types/expected_keepers.go | 5 +++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/app.go b/app/app.go index 910d7b9b2..826148d51 100644 --- a/app/app.go +++ b/app/app.go @@ -244,7 +244,7 @@ func NewInitApp( // Engine's module keepers app.ownershipKeeper = ownership.NewKeeper(app.cdc, keys[ownership.StoreKey], app.bankKeeper) app.instanceKeeper = instance.NewKeeper(app.cdc, keys[instance.StoreKey]) - app.processKeeper = process.NewKeeper(app.cdc, keys[process.StoreKey], app.instanceKeeper, app.ownershipKeeper) + app.processKeeper = process.NewKeeper(app.cdc, keys[process.StoreKey], app.instanceKeeper, app.ownershipKeeper, app.bankKeeper) app.serviceKeeper = service.NewKeeper(app.cdc, keys[service.StoreKey], app.ownershipKeeper) app.runnerKeeper = runner.NewKeeper(app.cdc, keys[runner.StoreKey], app.instanceKeeper, app.ownershipKeeper) app.executionKeeper = execution.NewKeeper( diff --git a/config/config.go b/config/config.go index fa441aa4a..9e1aed9b3 100644 --- a/config/config.go +++ b/config/config.go @@ -97,7 +97,7 @@ func defaultConfig() (*Config, error) { c.IpfsEndpoint = "http://ipfs.app.mesg.com:8080/ipfs/" - c.DefaultExecutionPrice = "10000atto" // /x/execution/internal/type/params.go#DefaultMinPrice + c.DefaultExecutionPrice = "10000atto" // /x/execution/internal/types/params.go#DefaultMinPrice c.Server.Address = ":50052" c.Log.Format = "text" diff --git a/x/process/internal/keeper/keeper.go b/x/process/internal/keeper/keeper.go index 8d2ce7dbd..dfe075bd0 100644 --- a/x/process/internal/keeper/keeper.go +++ b/x/process/internal/keeper/keeper.go @@ -10,24 +10,29 @@ import ( "github.com/mesg-foundation/engine/process" processpb "github.com/mesg-foundation/engine/process" "github.com/mesg-foundation/engine/x/process/internal/types" + "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/log" ) +var processCreateInitialBalance = "10000000atto" + // Keeper of the process store type Keeper struct { storeKey sdk.StoreKey cdc *codec.Codec ownershipKeeper types.OwnershipKeeper instanceKeeper types.InstanceKeeper + bankKeeper types.BankKeeper } // NewKeeper creates a process keeper -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, instanceKeeper types.InstanceKeeper, ownershipKeeper types.OwnershipKeeper) Keeper { +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, instanceKeeper types.InstanceKeeper, ownershipKeeper types.OwnershipKeeper, bankKeeper types.BankKeeper) Keeper { keeper := Keeper{ storeKey: key, cdc: cdc, instanceKeeper: instanceKeeper, ownershipKeeper: ownershipKeeper, + bankKeeper: bankKeeper, } return keeper } @@ -67,6 +72,15 @@ func (k Keeper) Create(ctx sdk.Context, msg *types.MsgCreateProcess) (*processpb } } + procAddress := sdk.AccAddress(crypto.AddressHash(p.Hash)) + procInitBal, err := sdk.ParseCoins(processCreateInitialBalance) + if err != nil { + return nil, err + } + if err := k.bankKeeper.SendCoins(ctx, msg.Owner, procAddress, procInitBal); err != nil { + return nil, err + } + value, err := k.cdc.MarshalBinaryLengthPrefixed(p) if err != nil { return nil, err diff --git a/x/process/internal/types/expected_keepers.go b/x/process/internal/types/expected_keepers.go index fc0ec8169..88ae91310 100644 --- a/x/process/internal/types/expected_keepers.go +++ b/x/process/internal/types/expected_keepers.go @@ -26,3 +26,8 @@ type OwnershipKeeper interface { Delete(ctx sdk.Context, owner sdk.AccAddress, resourceHash hash.Hash) error Set(ctx sdk.Context, owner sdk.AccAddress, resourceHash hash.Hash, resource ownershippb.Ownership_Resource) (*ownershippb.Ownership, error) } + +// BankKeeper module interface. +type BankKeeper interface { + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error +} From caebc2b7325a98c8c6e6eb5796b28e0dda68e94b Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Fri, 13 Mar 2020 15:43:14 +0700 Subject: [PATCH 4/5] update e2e test --- e2e/api_test.go | 9 +++++---- e2e/execution_test.go | 8 ++++---- ...o => orchestrator_balance_withdraw_test.go} | 18 +++++++----------- e2e/orchestrator_event_task_test.go | 13 ------------- e2e/orchestrator_filter_test.go | 13 ------------- e2e/orchestrator_map_const_test.go | 13 ------------- e2e/orchestrator_nested_data_test.go | 13 ------------- e2e/orchestrator_nested_map_test.go | 13 ------------- e2e/orchestrator_ref_grand_parent_task_test.go | 16 ---------------- e2e/orchestrator_ref_path_nested_test.go | 14 -------------- e2e/orchestrator_result_task_test.go | 14 -------------- e2e/orchestrator_test.go | 2 +- e2e/process_test.go | 17 +++++++++++++++++ e2e/runner_test.go | 9 +++++++++ 14 files changed, 43 insertions(+), 129 deletions(-) rename e2e/{orchestrator_withdraw_test.go => orchestrator_balance_withdraw_test.go} (83%) diff --git a/e2e/api_test.go b/e2e/api_test.go index 805ddd705..7f09746da 100644 --- a/e2e/api_test.go +++ b/e2e/api_test.go @@ -32,10 +32,11 @@ type apiclient struct { } var ( - minExecutionPrice sdk.Coins - client apiclient - cclient *cosmos.Client - cdc = app.MakeCodec() + minExecutionPrice sdk.Coins + client apiclient + cclient *cosmos.Client + cdc = app.MakeCodec() + processInitialBalance = sdk.NewCoins(sdk.NewInt64Coin("atto", 10000000)) ) const ( diff --git a/e2e/execution_test.go b/e2e/execution_test.go index 4674b1916..5ce43d521 100644 --- a/e2e/execution_test.go +++ b/e2e/execution_test.go @@ -222,7 +222,7 @@ func testExecution(t *testing.T) { t.Run("execution balance before completed", func(t *testing.T) { coins := sdk.Coins{} lcdGet(t, "bank/balances/"+execAddress.String(), &coins) - require.True(t, coins.AmountOf("atto").Equal(sdk.NewInt(50000))) + require.True(t, coins.AmountOf("atto").Equal(sdk.NewInt(50000)), coins) }) var executorBalance sdk.Coins @@ -241,20 +241,20 @@ func testExecution(t *testing.T) { t.Run("executor balance", func(t *testing.T) { coins := sdk.Coins{} lcdGet(t, "bank/balances/"+executorAddress.String(), &coins) - require.True(t, coins.AmountOf("atto").Equal(sdk.NewInt(45000).Add(executorBalance.AmountOf("atto")))) + require.True(t, coins.AmountOf("atto").Equal(sdk.NewInt(45000).Add(executorBalance.AmountOf("atto"))), coins) }) // check balance of service t.Run("service balance", func(t *testing.T) { coins := sdk.Coins{} lcdGet(t, "bank/balances/"+serviceAddress.String(), &coins) - require.True(t, coins.AmountOf("atto").Equal(sdk.NewInt(5000).Add(serviceBalance.AmountOf("atto")))) + require.True(t, coins.AmountOf("atto").Equal(sdk.NewInt(5000).Add(serviceBalance.AmountOf("atto"))), coins) }) // check balance of execution t.Run("execution balance", func(t *testing.T) { coins := sdk.Coins{} execAddress := sdk.AccAddress(crypto.AddressHash(resp.Hash)) lcdGet(t, "bank/balances/"+execAddress.String(), &coins) - require.True(t, coins.AmountOf("atto").Equal(sdk.NewInt(0))) + require.True(t, coins.AmountOf("atto").Equal(sdk.NewInt(0)), coins) }) t.Run("withdraw from service", func(t *testing.T) { diff --git a/e2e/orchestrator_withdraw_test.go b/e2e/orchestrator_balance_withdraw_test.go similarity index 83% rename from e2e/orchestrator_withdraw_test.go rename to e2e/orchestrator_balance_withdraw_test.go index 37619024b..b3a397fc5 100644 --- a/e2e/orchestrator_withdraw_test.go +++ b/e2e/orchestrator_balance_withdraw_test.go @@ -16,7 +16,7 @@ import ( "github.com/tendermint/tendermint/crypto" ) -func testOrchestratorProcessWithdraw(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { +func testOrchestratorProcessBalanceWithdraw(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) { return func(t *testing.T) { var processHash hash.Hash @@ -50,16 +50,12 @@ func testOrchestratorProcessWithdraw(executionStream pb.Execution_StreamClient, 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("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.IsEqual(processInitialBalance), coins) }) - t.Run("trigger process", func(t *testing.T) { _, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{ InstanceHash: instanceHash, @@ -97,7 +93,7 @@ func testOrchestratorProcessWithdraw(executionStream pb.Execution_StreamClient, 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()) + require.True(t, coins.IsEqual(processInitialBalance.Sub(minExecutionPrice)), coins) }) t.Run("delete process", func(t *testing.T) { _, err := client.ProcessClient.Delete(context.Background(), &pb.DeleteProcessRequest{Hash: processHash}) diff --git a/e2e/orchestrator_event_task_test.go b/e2e/orchestrator_event_task_test.go index 619800ceb..2b5246004 100644 --- a/e2e/orchestrator_event_task_test.go +++ b/e2e/orchestrator_event_task_test.go @@ -5,15 +5,12 @@ 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) { @@ -50,16 +47,6 @@ 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 0a7c75e77..f89b2dc07 100644 --- a/e2e/orchestrator_filter_test.go +++ b/e2e/orchestrator_filter_test.go @@ -6,15 +6,12 @@ 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) { @@ -66,16 +63,6 @@ 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 7d761cc1d..cf9c73ebc 100644 --- a/e2e/orchestrator_map_const_test.go +++ b/e2e/orchestrator_map_const_test.go @@ -5,15 +5,12 @@ 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) { @@ -65,16 +62,6 @@ 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 2ef365966..062a86d6d 100644 --- a/e2e/orchestrator_nested_data_test.go +++ b/e2e/orchestrator_nested_data_test.go @@ -5,15 +5,12 @@ 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) { @@ -81,16 +78,6 @@ 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 f8dd257ec..34239c3fe 100644 --- a/e2e/orchestrator_nested_map_test.go +++ b/e2e/orchestrator_nested_map_test.go @@ -4,15 +4,12 @@ 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) { @@ -108,16 +105,6 @@ 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 e6924c1e1..861f0af05 100644 --- a/e2e/orchestrator_ref_grand_parent_task_test.go +++ b/e2e/orchestrator_ref_grand_parent_task_test.go @@ -5,15 +5,12 @@ 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) { @@ -106,19 +103,6 @@ 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 4e15db361..1b5d8bad9 100644 --- a/e2e/orchestrator_ref_path_nested_test.go +++ b/e2e/orchestrator_ref_path_nested_test.go @@ -5,15 +5,12 @@ 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) { @@ -227,17 +224,6 @@ 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 0a74b8fa9..65eb4b06c 100644 --- a/e2e/orchestrator_result_task_test.go +++ b/e2e/orchestrator_result_task_test.go @@ -4,15 +4,12 @@ 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) { @@ -49,17 +46,6 @@ 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 77de52ece..10fc00b16 100644 --- a/e2e/orchestrator_test.go +++ b/e2e/orchestrator_test.go @@ -15,7 +15,7 @@ func testOrchestrator(t *testing.T) { acknowledgement.WaitForStreamToBeReady(executionStream) // running orchestrator tests - t.Run("withdraw from process", testOrchestratorProcessWithdraw(executionStream, testInstanceHash)) + t.Run("process balance and withdraw", testOrchestratorProcessBalanceWithdraw(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/process_test.go b/e2e/process_test.go index 0b1d89aff..8a311a80a 100644 --- a/e2e/process_test.go +++ b/e2e/process_test.go @@ -4,11 +4,14 @@ import ( "context" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/ownership" "github.com/mesg-foundation/engine/process" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) var testProcessHash hash.Hash @@ -102,6 +105,13 @@ func testProcess(t *testing.T) { }) }) + 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.IsEqual(processInitialBalance), coins) + }) + t.Run("list", func(t *testing.T) { t.Run("grpc", func(t *testing.T) { ps, err := client.ProcessClient.List(context.Background(), &pb.ListProcessRequest{}) @@ -132,4 +142,11 @@ func testProcess(t *testing.T) { require.Len(t, ownerships.Ownerships, 2) }) }) + + 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(), coins) + }) } diff --git a/e2e/runner_test.go b/e2e/runner_test.go index 02642eed4..1c7550841 100644 --- a/e2e/runner_test.go +++ b/e2e/runner_test.go @@ -4,11 +4,14 @@ import ( "context" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/protobuf/acknowledgement" pb "github.com/mesg-foundation/engine/protobuf/api" "github.com/mesg-foundation/engine/runner" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" ) var testRunnerHash hash.Hash @@ -93,4 +96,10 @@ func testDeleteRunner(t *testing.T) { lcdGet(t, "runner/list", &rs) require.Len(t, rs, 0) }) + t.Run("check coins on runner", func(t *testing.T) { + var coins sdk.Coins + param := bank.NewQueryBalanceParams(sdk.AccAddress(crypto.AddressHash(testRunnerHash))) + require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins)) + require.True(t, coins.IsZero(), coins) + }) } From 46623cf4606896f07456aa3d3af66f0f005fc7de Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Fri, 13 Mar 2020 15:45:16 +0700 Subject: [PATCH 5/5] add balance check on process deletion --- e2e/orchestrator_balance_withdraw_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/e2e/orchestrator_balance_withdraw_test.go b/e2e/orchestrator_balance_withdraw_test.go index b3a397fc5..d1574181b 100644 --- a/e2e/orchestrator_balance_withdraw_test.go +++ b/e2e/orchestrator_balance_withdraw_test.go @@ -89,7 +89,7 @@ func testOrchestratorProcessBalanceWithdraw(executionStream pb.Execution_StreamC 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) { + t.Run("check coins on process after 1 execution", 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)) @@ -99,5 +99,11 @@ func testOrchestratorProcessBalanceWithdraw(executionStream pb.Execution_StreamC _, err := client.ProcessClient.Delete(context.Background(), &pb.DeleteProcessRequest{Hash: processHash}) require.NoError(t, err) }) + t.Run("check coins on process after deletion", 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(), coins) + }) } }