From eb1dfef2967d43916c0d1d09df6bcbc8ccfb19ae Mon Sep 17 00:00:00 2001 From: Warren He Date: Wed, 23 Mar 2022 17:03:05 -0700 Subject: [PATCH] floating, need to set gas --- tests/e2e/inmsgstest.go | 74 +++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/tests/e2e/inmsgstest.go b/tests/e2e/inmsgstest.go index f3c817d83d..d6cf062228 100644 --- a/tests/e2e/inmsgstest.go +++ b/tests/e2e/inmsgstest.go @@ -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" @@ -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() @@ -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(), @@ -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 }