Skip to content

Commit

Permalink
floating, need to set gas
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Mar 24, 2022
1 parent 71232b2 commit eb1dfef
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions tests/e2e/inmsgstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"google.golang.org/grpc"

"github.com/oasisprotocol/oasis-core/go/common/cbor"
Expand All @@ -16,11 +17,36 @@ import (
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/modules/accounts"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/testing"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
)

func makeRuntimeTransferCheck(from types.Address, to types.Address, amount types.BaseUnits) func(e client.DecodedEvent) bool {
return func(e client.DecodedEvent) bool {
ae, ok := e.(*accounts.Event)
if !ok {
return false
}
if ae.Transfer == nil {
return false
}
if !ae.Transfer.From.Equal(from) {
return false
}
if !ae.Transfer.To.Equal(to) {
return false
}
if ae.Transfer.Amount.Amount.Cmp(&amount.Amount) != 0 {
return false
}
if ae.Transfer.Amount.Denomination != amount.Denomination {
return false
}
return true
}
}

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()
Expand All @@ -30,34 +56,56 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
ch, sub, err := stakingClient.WatchEvents(ctx)
defer sub.Close()
if err != nil {
return err
return fmt.Errorf("staking client watch events: %w", err)
}

consDenomination := types.Denomination("TEST")

consAccounts := consensusAccounts.NewV1(rtc)
ac := accounts.NewV1(rtc)

acCh, err := rtc.WatchEvents(ctx, []client.EventDecoder{consAccounts}, false)
acCh, err := rtc.WatchEvents(ctx, []client.EventDecoder{ac}, false)
if err != nil {
return err
return fmt.Errorf("runtime client watch events: %w", err)
}

runtimeAddr := staking.NewRuntimeAddress(runtimeID)

// Message with no embedded transaction.
// Message with transfer.
transferAmount := types.NewBaseUnits(*quantity.NewFromUint64(10_000), consDenomination)
tb := ac.Transfer(testing.Bob.Address, transferAmount)
tb.AppendAuthSignature(testing.Alice.SigSpec, 2)
if err = tb.AppendSign(ctx, testing.Alice.Signer); err != nil {
return fmt.Errorf("msg 1 embedded transfer append sign: %w", err)
}
ut := cbor.Marshal(tb.GetUnverifiedTransaction())
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()),
Data: cbor.Marshal(types.IncomingMessageData{
Versioned: cbor.NewVersioned(types.LatestIncomingMessageVersion),
UnverifiedTransaction: &ut,
}),
}))
if err != nil {
return fmt.Errorf("msg 1 submit sign: %w", err)
}

theirChainContext, err := cons.GetChainContext(ctx)
if err != nil {
return err
}
if err = cons.SubmitTx(ctx, signedTx); err != nil {
log.Warn("their chain context", "context", theirChainContext)
ourSignerContext, err := signature.PrepareSignerContext(transaction.SignatureContext)
if err != nil {
return err
}
log.Warn("our signer context", "context", string(ourSignerContext))

if err = cons.SubmitTx(ctx, signedTx); err != nil {
return fmt.Errorf("msg 1 submit: %w", err)
}
aliceAccount, err := cons.Staking().Account(ctx, &staking.OwnerQuery{
Height: consensus.HeightLatest,
Owner: testing.Alice.Address.ConsensusAddress(),
Expand All @@ -67,14 +115,20 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
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...
if err = ensureRuntimeEvent(log, acCh, makeRuntimeTransferCheck(testing.Alice.Address, testing.Bob.Address, transferAmount)); err != nil {
return fmt.Errorf("after msg 1 wait for transfer event: %w", err)
}

// %%%
_ = ch
_ = runtimeAddr

// 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
// - too much gas: funds should work

return nil
}

0 comments on commit eb1dfef

Please sign in to comment.