55 "fmt"
66 "time"
77
8- "github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
98 "google.golang.org/grpc"
109
1110 "github.com/oasisprotocol/oasis-core/go/common/cbor"
@@ -22,6 +21,28 @@ import (
2221 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
2322)
2423
24+ func makeMintCheck (owner types.Address , amount types.BaseUnits ) func (e client.DecodedEvent ) bool {
25+ return func (e client.DecodedEvent ) bool {
26+ ae , ok := e .(* accounts.Event )
27+ if ! ok {
28+ return false
29+ }
30+ if ae .Mint == nil {
31+ return false
32+ }
33+ if ! ae .Mint .Owner .Equal (owner ) {
34+ return false
35+ }
36+ if ae .Mint .Amount .Amount .Cmp (& amount .Amount ) != 0 {
37+ return false
38+ }
39+ if ae .Mint .Amount .Denomination != amount .Denomination {
40+ return false
41+ }
42+ return true
43+ }
44+ }
45+
2546func makeRuntimeTransferCheck (from types.Address , to types.Address , amount types.BaseUnits ) func (e client.DecodedEvent ) bool {
2647 return func (e client.DecodedEvent ) bool {
2748 ae , ok := e .(* accounts.Event )
@@ -70,15 +91,24 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
7091
7192 runtimeAddr := staking .NewRuntimeAddress (runtimeID )
7293
94+ log .Warn ("0: get alice starting balance" )
95+ aliceAccount , err := cons .Staking ().Account (ctx , & staking.OwnerQuery {
96+ Height : consensus .HeightLatest ,
97+ Owner : testing .Alice .Address .ConsensusAddress (),
98+ })
99+ aliceExpectedBalance := aliceAccount .General .Balance
100+
73101 // Message with transfer.
74- transferAmount := types .NewBaseUnits (* quantity .NewFromUint64 (10_000 ), consDenomination )
102+ transferAmount := types .NewBaseUnits (* quantity .NewFromUint64 (100_000 ), consDenomination )
75103 tb := ac .Transfer (testing .Bob .Address , transferAmount )
76104 tb .AppendAuthSignature (testing .Alice .SigSpec , 2 )
77105 if err = tb .AppendSign (ctx , testing .Alice .Signer ); err != nil {
78106 return fmt .Errorf ("msg 1 embedded transfer append sign: %w" , err )
79107 }
80108 ut := cbor .Marshal (tb .GetUnverifiedTransaction ())
81- signedTx , err := transaction .Sign (testing .Alice .ConsensusSigner , roothash .NewSubmitMsgTx (0 , nil , & roothash.SubmitMsg {
109+ signedTx , err := transaction .Sign (testing .Alice .ConsensusSigner , roothash .NewSubmitMsgTx (0 , & transaction.Fee {
110+ Gas : 2000 ,
111+ }, & roothash.SubmitMsg {
82112 ID : runtimeID ,
83113 Tag : 0 ,
84114 Fee : * quantity .NewFromUint64 (1 ),
@@ -91,29 +121,24 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
91121 if err != nil {
92122 return fmt .Errorf ("msg 1 submit sign: %w" , err )
93123 }
94-
95- theirChainContext , err := cons .GetChainContext (ctx )
96- if err != nil {
97- return err
98- }
99- log .Warn ("their chain context" , "context" , theirChainContext )
100- ourSignerContext , err := signature .PrepareSignerContext (transaction .SignatureContext )
101- if err != nil {
102- return err
103- }
104- log .Warn ("our signer context" , "context" , string (ourSignerContext ))
105-
106124 if err = cons .SubmitTx (ctx , signedTx ); err != nil {
107125 return fmt .Errorf ("msg 1 submit: %w" , err )
108126 }
109- aliceAccount , err := cons .Staking ().Account (ctx , & staking.OwnerQuery {
127+ if err = aliceExpectedBalance .Sub (quantity .NewFromUint64 (11 )); err != nil {
128+ return fmt .Errorf ("msg 1 decreasing expected balance: %w" , err )
129+ }
130+
131+ log .Warn ("1: alice get balance" )
132+ aliceAccount , err = cons .Staking ().Account (ctx , & staking.OwnerQuery {
110133 Height : consensus .HeightLatest ,
111134 Owner : testing .Alice .Address .ConsensusAddress (),
112135 })
113136 // todo: figure out what consensus balance should be. 1 million minus something from previous tests
114- expectedBalance := quantity .NewFromUint64 (89 )
115- if aliceAccount .General .Balance .Cmp (expectedBalance ) != 0 {
116- return fmt .Errorf ("after message 1: alice consensus balance expected %v actual %v" , expectedBalance , aliceAccount .General .Balance )
137+ if aliceAccount .General .Balance .Cmp (& aliceExpectedBalance ) != 0 {
138+ return fmt .Errorf ("after message 1: alice consensus balance expected %v actual %v" , aliceExpectedBalance , aliceAccount .General .Balance )
139+ }
140+ if err = ensureRuntimeEvent (log , acCh , makeMintCheck (testing .Alice .Address , transferAmount )); err != nil {
141+ return fmt .Errorf ("after msg 1 wait for mint event: %w" , err )
117142 }
118143 if err = ensureRuntimeEvent (log , acCh , makeRuntimeTransferCheck (testing .Alice .Address , testing .Bob .Address , transferAmount )); err != nil {
119144 return fmt .Errorf ("after msg 1 wait for transfer event: %w" , err )
0 commit comments