Skip to content

Commit

Permalink
(unfinished) incoming message tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Mar 23, 2022
1 parent ce5f7c5 commit 6c0824f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
80 changes: 80 additions & 0 deletions tests/e2e/inmsgstest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package main

import (
"context"
"fmt"
"time"

"google.golang.org/grpc"

"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/common/quantity"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"

"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
consensusAccounts "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/consensusaccounts"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/testing"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
)

func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.ClientConn, rtc client.RuntimeClient) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

cons := consensus.NewConsensusClient(conn)
stakingClient := cons.Staking()
ch, sub, err := stakingClient.WatchEvents(ctx)
defer sub.Close()
if err != nil {
return err
}

consDenomination := types.Denomination("TEST")

consAccounts := consensusAccounts.NewV1(rtc)

acCh, err := rtc.WatchEvents(ctx, []client.EventDecoder{consAccounts}, false)
if err != nil {
return err
}

runtimeAddr := staking.NewRuntimeAddress(runtimeID)

// Message with no embedded transaction.
signedTx, err := transaction.Sign(testing.Alice.ConsensusSigner, roothash.NewSubmitMsgTx(0, nil, &roothash.SubmitMsg{
ID: runtimeID,
Tag: 0,
Fee: *quantity.NewFromUint64(1),
Tokens: *quantity.NewFromUint64(10),
Data: cbor.Marshal(types.NoopIncomingMessageData()),
}))
if err != nil {
return err
}
if err = cons.SubmitTx(ctx, signedTx); err != nil {
return err
}
aliceAccount, err := cons.Staking().Account(ctx, &staking.OwnerQuery{
Height: consensus.HeightLatest,
Owner: testing.Alice.Address.ConsensusAddress(),
})
// todo: figure out what consensus balance should be. 1 million minus something from previous tests
expectedBalance := quantity.NewFromUint64(89)
if aliceAccount.General.Balance.Cmp(expectedBalance) != 0 {
return fmt.Errorf("after message 1: alice consensus balance expected %v actual %v", expectedBalance, aliceAccount.General.Balance)
}
// todo: need event to watch for mint...

// todo: test other cases
// - embedded transfer, different sender: should execute
// - malformed data field: funds should work
// - invalid transaction: funds should work
// - failed transaction: funds should work
// - too much has: funds should work

return nil
}
2 changes: 1 addition & 1 deletion tests/e2e/scenarios.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
})

// SimpleConsensusRuntime is the simple-consensus runtime test.
SimpleConsensusRuntime *RuntimeScenario = NewRuntimeScenario("test-runtime-simple-consensus", []RunTestFunction{SimpleConsensusTest, ConsensusAccountsParametersTest})
SimpleConsensusRuntime *RuntimeScenario = NewRuntimeScenario("test-runtime-simple-consensus", []RunTestFunction{SimpleConsensusTest, ConsensusAccountsParametersTest, IncomingMessagesTest})

// SimpleEVMRuntime is the simple-evm runtime test.
SimpleEVMRuntime *RuntimeScenario = NewRuntimeScenario("test-runtime-simple-evm", []RunTestFunction{
Expand Down

0 comments on commit 6c0824f

Please sign in to comment.