Skip to content

Commit

Permalink
Add and fix tests for processes
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Mar 4, 2020
1 parent d9e4ce9 commit 752c23b
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 3 deletions.
11 changes: 8 additions & 3 deletions e2e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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())
Expand Down
13 changes: 13 additions & 0 deletions e2e/orchestrator_event_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions e2e/orchestrator_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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{
Expand Down
13 changes: 13 additions & 0 deletions e2e/orchestrator_map_const_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions e2e/orchestrator_nested_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions e2e/orchestrator_nested_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions e2e/orchestrator_ref_grand_parent_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions e2e/orchestrator_ref_path_nested_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions e2e/orchestrator_result_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions e2e/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading

0 comments on commit 752c23b

Please sign in to comment.