Skip to content

Commit

Permalink
floating
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Mar 18, 2022
1 parent 5a84fba commit 22f9cdd
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions tests/e2e/inmsgstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,37 @@ import (
staking "github.com/oasisprotocol/oasis-core/go/staking/api"

"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/accounts"
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 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 @@ -36,6 +62,7 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
consDenomination := types.Denomination("TEST")

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

acCh, err := rtc.WatchEvents(ctx, []client.EventDecoder{consAccounts}, false)
if err != nil {
Expand All @@ -44,13 +71,23 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C

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 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 err
Expand All @@ -67,14 +104,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 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 22f9cdd

Please sign in to comment.