Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add address to service, runner, execution, and execution #1728

Merged
merged 3 commits into from
Mar 16, 2020
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
4 changes: 2 additions & 2 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
db "github.com/tendermint/tm-db"
)

func stopRunningServices(mc *cosmos.ModuleClient, b *builder.Builder, address string) error {
runners, err := mc.ListRunner(&cosmos.FilterRunner{Address: address})
func stopRunningServices(mc *cosmos.ModuleClient, b *builder.Builder, owner string) error {
runners, err := mc.ListRunner(&cosmos.FilterRunner{Owner: owner})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cosmos/module_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (mc *ModuleClient) GetRunner(hash hash.Hash) (*runnerpb.Runner, error) {

// FilterRunner to apply while listing runners.
type FilterRunner struct {
Address string
Owner string
InstanceHash hash.Hash
}

Expand All @@ -277,7 +277,7 @@ func (mc *ModuleClient) ListRunner(f *FilterRunner) ([]*runnerpb.Runner, error)
// filter results
out := make([]*runnerpb.Runner, 0)
for _, r := range rs {
if (f.Address == "" || r.Address == f.Address) &&
if (f.Owner == "" || r.Owner == f.Owner) &&
(f.InstanceHash.IsZero() || r.InstanceHash.Equal(f.InstanceHash)) {
out = append(out, r)
}
Expand Down
21 changes: 12 additions & 9 deletions e2e/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/mesg-foundation/engine/protobuf/types"
"github.com/mesg-foundation/engine/x/ownership"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
)

func testExecution(t *testing.T) {
Expand All @@ -23,6 +22,7 @@ func testExecution(t *testing.T) {
streamCompleted pb.Execution_StreamClient
err error
executorHash = testRunnerHash
executorAddress = testRunnerAddress
)

t.Run("create stream nil filter", func(t *testing.T) {
Expand Down Expand Up @@ -214,9 +214,13 @@ func testExecution(t *testing.T) {
})
require.NoError(t, err)

execAddress := sdk.AccAddress(crypto.AddressHash(resp.Hash))
executorAddress := sdk.AccAddress(crypto.AddressHash(executorHash))
serviceAddress := sdk.AccAddress(crypto.AddressHash(testServiceHash))
var execAddress sdk.AccAddress
t.Run("get execution address", func(t *testing.T) {
var exec *execution.Execution
lcdGet(t, "execution/get/"+resp.Hash.String(), &exec)
require.Equal(t, exec.Hash, resp.Hash)
execAddress = exec.Address
})

// check balance of execution before completed
t.Run("execution balance before completed", func(t *testing.T) {
Expand All @@ -232,7 +236,7 @@ func testExecution(t *testing.T) {
var executorBalance sdk.Coins
var serviceBalance sdk.Coins
lcdGet(t, "bank/balances/"+executorAddress.String(), &executorBalance)
lcdGet(t, "bank/balances/"+serviceAddress.String(), &serviceBalance)
lcdGet(t, "bank/balances/"+testServiceAddress.String(), &serviceBalance)

_, err = streamInProgress.Recv()
require.NoError(t, err)
Expand All @@ -250,13 +254,12 @@ func testExecution(t *testing.T) {
// check balance of service
t.Run("service balance", func(t *testing.T) {
coins := sdk.Coins{}
lcdGet(t, "bank/balances/"+serviceAddress.String(), &coins)
lcdGet(t, "bank/balances/"+testServiceAddress.String(), &coins)
require.True(t, coins.AmountOf("atto").Equal(expectedCoinsForService.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)), coins)
})
Expand All @@ -269,7 +272,7 @@ func testExecution(t *testing.T) {
_, err = cclient.BuildAndBroadcastMsg(msg)
require.NoError(t, err)

param := bank.NewQueryBalanceParams(sdk.AccAddress(crypto.AddressHash(testServiceHash)))
param := bank.NewQueryBalanceParams(testServiceAddress)
require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins))
require.True(t, coins.AmountOf("atto").Equal(serviceBalance.AmountOf("atto")), coins)
})
Expand All @@ -282,7 +285,7 @@ func testExecution(t *testing.T) {
_, err = cclient.BuildAndBroadcastMsg(msg)
require.NoError(t, err)

param := bank.NewQueryBalanceParams(sdk.AccAddress(crypto.AddressHash(testRunnerHash)))
param := bank.NewQueryBalanceParams(testRunnerAddress)
require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins))
require.True(t, coins.AmountOf("atto").Equal(executorBalance.AmountOf("atto")), coins)
})
Expand Down
18 changes: 13 additions & 5 deletions e2e/orchestrator_balance_withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (
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 testOrchestratorProcessBalanceWithdraw(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) {
return func(t *testing.T) {
var processHash hash.Hash
var (
processHash hash.Hash
procAddress sdk.AccAddress
)

t.Run("create process", func(t *testing.T) {
respProc, err := client.ProcessClient.Create(context.Background(), &pb.CreateProcessRequest{
Expand Down Expand Up @@ -50,9 +52,15 @@ func testOrchestratorProcessBalanceWithdraw(executionStream pb.Execution_StreamC
require.NoError(t, err)
processHash = respProc.Hash
})
t.Run("get process address", func(t *testing.T) {
var proc *process.Process
lcdGet(t, "process/get/"+processHash.String(), &proc)
require.Equal(t, proc.Hash, processHash)
procAddress = proc.Address
})
t.Run("check coins on process", func(t *testing.T) {
var coins sdk.Coins
param := bank.NewQueryBalanceParams(sdk.AccAddress(crypto.AddressHash(processHash)))
param := bank.NewQueryBalanceParams(procAddress)
require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins))
require.True(t, coins.IsEqual(processInitialBalance), coins)
})
Expand Down Expand Up @@ -91,7 +99,7 @@ func testOrchestratorProcessBalanceWithdraw(executionStream pb.Execution_StreamC
})
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)))
param := bank.NewQueryBalanceParams(procAddress)
require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins))
require.True(t, coins.IsEqual(processInitialBalance.Sub(minExecutionPrice)), coins)
})
Expand All @@ -101,7 +109,7 @@ func testOrchestratorProcessBalanceWithdraw(executionStream pb.Execution_StreamC
})
t.Run("check coins on process after deletion", func(t *testing.T) {
var coins sdk.Coins
param := bank.NewQueryBalanceParams(sdk.AccAddress(crypto.AddressHash(processHash)))
param := bank.NewQueryBalanceParams(procAddress)
require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins))
require.True(t, coins.IsZero(), coins)
})
Expand Down
26 changes: 12 additions & 14 deletions e2e/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
"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

func testProcess(t *testing.T) {
var (
processHash hash.Hash
req = &pb.CreateProcessRequest{
processHash hash.Hash
processAddress sdk.AccAddress
req = &pb.CreateProcessRequest{
Name: "test-process",
Nodes: []*process.Process_Node{
{
Expand Down Expand Up @@ -53,32 +51,32 @@ func testProcess(t *testing.T) {
t.Run("create", func(t *testing.T) {
resp, err := client.ProcessClient.Create(context.Background(), req)
require.NoError(t, err)
testProcessHash = resp.Hash
processHash = resp.Hash
})

t.Run("get", func(t *testing.T) {
t.Run("grpc", func(t *testing.T) {
p, err := client.ProcessClient.Get(context.Background(), &pb.GetProcessRequest{Hash: testProcessHash})
p, err := client.ProcessClient.Get(context.Background(), &pb.GetProcessRequest{Hash: processHash})
require.NoError(t, err)
require.True(t, p.Equal(&process.Process{
Hash: p.Hash,
Address: sdk.AccAddress(crypto.AddressHash(p.Hash)).String(),
Address: p.Address,
Name: req.Name,
Nodes: req.Nodes,
Edges: req.Edges,
}))
processHash = p.Hash
})
t.Run("lcd", func(t *testing.T) {
var p *process.Process
lcdGet(t, "process/get/"+testProcessHash.String(), &p)
lcdGet(t, "process/get/"+processHash.String(), &p)
require.True(t, p.Equal(&process.Process{
Hash: p.Hash,
Address: sdk.AccAddress(crypto.AddressHash(p.Hash)).String(),
Address: p.Address,
Name: req.Name,
Nodes: req.Nodes,
Edges: req.Edges,
}))
processAddress = p.Address
})
})

Expand Down Expand Up @@ -109,7 +107,7 @@ 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)))
param := bank.NewQueryBalanceParams(processAddress)
require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins))
require.True(t, coins.IsEqual(processInitialBalance), coins)
})
Expand All @@ -128,7 +126,7 @@ func testProcess(t *testing.T) {
})

t.Run("delete", func(t *testing.T) {
_, err := client.ProcessClient.Delete(context.Background(), &pb.DeleteProcessRequest{Hash: testProcessHash})
_, err := client.ProcessClient.Delete(context.Background(), &pb.DeleteProcessRequest{Hash: processHash})
require.NoError(t, err)
})

Expand All @@ -147,7 +145,7 @@ 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)))
param := bank.NewQueryBalanceParams(processAddress)
require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins))
require.True(t, coins.IsZero(), coins)
})
Expand Down
5 changes: 3 additions & 2 deletions e2e/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
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
var testRunnerAddress sdk.AccAddress

func testRunner(t *testing.T) {
t.Run("create", func(t *testing.T) {
Expand Down Expand Up @@ -60,6 +60,7 @@ func testRunner(t *testing.T) {
var r *runner.Runner
lcdGet(t, "runner/get/"+testRunnerHash.String(), &r)
require.Equal(t, testRunnerHash, r.Hash)
testRunnerAddress = r.Address
})
})

Expand Down Expand Up @@ -98,7 +99,7 @@ func testDeleteRunner(t *testing.T) {
})
t.Run("check coins on runner", func(t *testing.T) {
var coins sdk.Coins
param := bank.NewQueryBalanceParams(sdk.AccAddress(crypto.AddressHash(testRunnerHash)))
param := bank.NewQueryBalanceParams(testRunnerAddress)
require.NoError(t, cclient.QueryJSON("custom/bank/balances", param, &coins))
require.True(t, coins.IsZero(), coins)
})
Expand Down
7 changes: 6 additions & 1 deletion e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import (
"context"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/ownership"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/service"
"github.com/stretchr/testify/require"
)

var testServiceHash hash.Hash
var (
testServiceHash hash.Hash
testServiceAddress sdk.AccAddress
)

func testService(t *testing.T) {
req := newTestCreateServiceRequest()
Expand All @@ -32,6 +36,7 @@ func testService(t *testing.T) {
var s *service.Service
lcdGet(t, "service/get/"+testServiceHash.String(), &s)
require.Equal(t, testServiceHash, s.Hash)
testServiceAddress = s.Address
})
})

Expand Down
5 changes: 4 additions & 1 deletion execution/execution.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package execution

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/protobuf/types"
"github.com/tendermint/tendermint/crypto"
)

// New returns a new execution. It returns an error if inputs are invalid.
// New returns a new execution.
func New(processHash, instanceHash, parentHash, eventHash hash.Hash, nodeKey, taskKey, price string, inputs *types.Struct, tags []string, executorHash hash.Hash) *Execution {
exec := &Execution{
ProcessHash: processHash,
Expand All @@ -21,6 +23,7 @@ func New(processHash, instanceHash, parentHash, eventHash hash.Hash, nodeKey, ta
ExecutorHash: executorHash,
}
exec.Hash = hash.Dump(exec)
exec.Address = sdk.AccAddress(crypto.AddressHash(exec.Hash))
return exec
}

Expand Down
Loading