Skip to content

Commit 22f9cdd

Browse files
committed
floating
1 parent 5a84fba commit 22f9cdd

1 file changed

Lines changed: 47 additions & 4 deletions

File tree

tests/e2e/inmsgstest.go

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,37 @@ import (
1616
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
1717

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

3864
consAccounts := consensusAccounts.NewV1(rtc)
65+
ac := accounts.NewV1(rtc)
3966

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

4572
runtimeAddr := staking.NewRuntimeAddress(runtimeID)
4673

47-
// Message with no embedded transaction.
74+
// Message with transfer.
75+
transferAmount := types.NewBaseUnits(*quantity.NewFromUint64(10_000), consDenomination)
76+
tb := ac.Transfer(testing.Bob.Address, transferAmount)
77+
tb.AppendAuthSignature(testing.Alice.SigSpec, 2)
78+
if err = tb.AppendSign(ctx, testing.Alice.Signer); err != nil {
79+
return err
80+
}
81+
ut := cbor.Marshal(tb.GetUnverifiedTransaction())
4882
signedTx, err := transaction.Sign(testing.Alice.ConsensusSigner, roothash.NewSubmitMsgTx(0, nil, &roothash.SubmitMsg{
4983
ID: runtimeID,
5084
Tag: 0,
5185
Fee: *quantity.NewFromUint64(1),
5286
Tokens: *quantity.NewFromUint64(10),
53-
Data: cbor.Marshal(types.NoopIncomingMessageData()),
87+
Data: cbor.Marshal(types.IncomingMessageData{
88+
Versioned: cbor.NewVersioned(types.LatestIncomingMessageVersion),
89+
UnverifiedTransaction: &ut,
90+
}),
5491
}))
5592
if err != nil {
5693
return err
@@ -67,14 +104,20 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
67104
if aliceAccount.General.Balance.Cmp(expectedBalance) != 0 {
68105
return fmt.Errorf("after message 1: alice consensus balance expected %v actual %v", expectedBalance, aliceAccount.General.Balance)
69106
}
70-
// todo: need event to watch for mint...
107+
if err = ensureRuntimeEvent(log, acCh, makeRuntimeTransferCheck(testing.Alice.Address, testing.Bob.Address, transferAmount)); err != nil {
108+
return err
109+
}
110+
111+
// %%%
112+
_ = ch
113+
_ = runtimeAddr
71114

72115
// todo: test other cases
73116
// - embedded transfer, different sender: should execute
74117
// - malformed data field: funds should work
75118
// - invalid transaction: funds should work
76119
// - failed transaction: funds should work
77-
// - too much has: funds should work
120+
// - too much gas: funds should work
78121

79122
return nil
80123
}

0 commit comments

Comments
 (0)