Skip to content

Commit eb1dfef

Browse files
committed
floating, need to set gas
1 parent 71232b2 commit eb1dfef

1 file changed

Lines changed: 64 additions & 10 deletions

File tree

tests/e2e/inmsgstest.go

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"time"
77

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

1011
"github.com/oasisprotocol/oasis-core/go/common/cbor"
@@ -16,11 +17,36 @@ import (
1617
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
1718

1819
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
19-
consensusAccounts "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/consensusaccounts"
20+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/accounts"
2021
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/testing"
2122
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
2223
)
2324

25+
func makeRuntimeTransferCheck(from types.Address, to types.Address, amount types.BaseUnits) func(e client.DecodedEvent) bool {
26+
return func(e client.DecodedEvent) bool {
27+
ae, ok := e.(*accounts.Event)
28+
if !ok {
29+
return false
30+
}
31+
if ae.Transfer == nil {
32+
return false
33+
}
34+
if !ae.Transfer.From.Equal(from) {
35+
return false
36+
}
37+
if !ae.Transfer.To.Equal(to) {
38+
return false
39+
}
40+
if ae.Transfer.Amount.Amount.Cmp(&amount.Amount) != 0 {
41+
return false
42+
}
43+
if ae.Transfer.Amount.Denomination != amount.Denomination {
44+
return false
45+
}
46+
return true
47+
}
48+
}
49+
2450
func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.ClientConn, rtc client.RuntimeClient) error {
2551
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
2652
defer cancel()
@@ -30,34 +56,56 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
3056
ch, sub, err := stakingClient.WatchEvents(ctx)
3157
defer sub.Close()
3258
if err != nil {
33-
return err
59+
return fmt.Errorf("staking client watch events: %w", err)
3460
}
3561

3662
consDenomination := types.Denomination("TEST")
3763

38-
consAccounts := consensusAccounts.NewV1(rtc)
64+
ac := accounts.NewV1(rtc)
3965

40-
acCh, err := rtc.WatchEvents(ctx, []client.EventDecoder{consAccounts}, false)
66+
acCh, err := rtc.WatchEvents(ctx, []client.EventDecoder{ac}, false)
4167
if err != nil {
42-
return err
68+
return fmt.Errorf("runtime client watch events: %w", err)
4369
}
4470

4571
runtimeAddr := staking.NewRuntimeAddress(runtimeID)
4672

47-
// Message with no embedded transaction.
73+
// Message with transfer.
74+
transferAmount := types.NewBaseUnits(*quantity.NewFromUint64(10_000), consDenomination)
75+
tb := ac.Transfer(testing.Bob.Address, transferAmount)
76+
tb.AppendAuthSignature(testing.Alice.SigSpec, 2)
77+
if err = tb.AppendSign(ctx, testing.Alice.Signer); err != nil {
78+
return fmt.Errorf("msg 1 embedded transfer append sign: %w", err)
79+
}
80+
ut := cbor.Marshal(tb.GetUnverifiedTransaction())
4881
signedTx, err := transaction.Sign(testing.Alice.ConsensusSigner, roothash.NewSubmitMsgTx(0, nil, &roothash.SubmitMsg{
4982
ID: runtimeID,
5083
Tag: 0,
5184
Fee: *quantity.NewFromUint64(1),
5285
Tokens: *quantity.NewFromUint64(10),
53-
Data: cbor.Marshal(types.NoopIncomingMessageData()),
86+
Data: cbor.Marshal(types.IncomingMessageData{
87+
Versioned: cbor.NewVersioned(types.LatestIncomingMessageVersion),
88+
UnverifiedTransaction: &ut,
89+
}),
5490
}))
91+
if err != nil {
92+
return fmt.Errorf("msg 1 submit sign: %w", err)
93+
}
94+
95+
theirChainContext, err := cons.GetChainContext(ctx)
5596
if err != nil {
5697
return err
5798
}
58-
if err = cons.SubmitTx(ctx, signedTx); err != nil {
99+
log.Warn("their chain context", "context", theirChainContext)
100+
ourSignerContext, err := signature.PrepareSignerContext(transaction.SignatureContext)
101+
if err != nil {
59102
return err
60103
}
104+
log.Warn("our signer context", "context", string(ourSignerContext))
105+
106+
if err = cons.SubmitTx(ctx, signedTx); err != nil {
107+
return fmt.Errorf("msg 1 submit: %w", err)
108+
}
61109
aliceAccount, err := cons.Staking().Account(ctx, &staking.OwnerQuery{
62110
Height: consensus.HeightLatest,
63111
Owner: testing.Alice.Address.ConsensusAddress(),
@@ -67,14 +115,20 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
67115
if aliceAccount.General.Balance.Cmp(expectedBalance) != 0 {
68116
return fmt.Errorf("after message 1: alice consensus balance expected %v actual %v", expectedBalance, aliceAccount.General.Balance)
69117
}
70-
// todo: need event to watch for mint...
118+
if err = ensureRuntimeEvent(log, acCh, makeRuntimeTransferCheck(testing.Alice.Address, testing.Bob.Address, transferAmount)); err != nil {
119+
return fmt.Errorf("after msg 1 wait for transfer event: %w", err)
120+
}
121+
122+
// %%%
123+
_ = ch
124+
_ = runtimeAddr
71125

72126
// todo: test other cases
73127
// - embedded transfer, different sender: should execute
74128
// - malformed data field: funds should work
75129
// - invalid transaction: funds should work
76130
// - failed transaction: funds should work
77-
// - too much has: funds should work
131+
// - too much gas: funds should work
78132

79133
return nil
80134
}

0 commit comments

Comments
 (0)