Skip to content

Commit 1e64608

Browse files
committed
floating, insufficient balance
1 parent 41110cb commit 1e64608

2 files changed

Lines changed: 51 additions & 20 deletions

File tree

runtime-sdk/src/dispatcher.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ impl<R: Runtime> Dispatcher<R> {
342342
data: &IncomingMessageData,
343343
tx: &Option<Transaction>,
344344
) -> Result<(), RuntimeError> {
345+
warn!(ctx.get_logger("dispatcher"), "incoming message executing"; "id" => in_msg.id); // %%%
345346
R::Modules::execute_in_msg(ctx, in_msg, data, tx)?;
347+
warn!(ctx.get_logger("dispatcher"), "incoming message modules done"; "id" => in_msg.id); // %%%
346348
if let Some(tx) = tx {
347349
let tx_size = match data
348350
.ut
@@ -359,7 +361,11 @@ impl<R: Runtime> Dispatcher<R> {
359361
};
360362
// Use the ID as index.
361363
let index = in_msg.id.try_into().unwrap();
362-
Self::execute_tx(ctx, tx_size, tx.clone(), index)?;
364+
let result = Self::execute_tx(ctx, tx_size, tx.clone(), index)?;
365+
let result_parsed = cbor::from_slice::<crate::types::transaction::CallResult>(&result.output).unwrap();
366+
warn!(ctx.get_logger("dispatcher"), "incoming message transaction done"; "id" => in_msg.id, "result_parsed" => ?result_parsed); // %%%
367+
} else {
368+
warn!(ctx.get_logger("dispatcher"), "incoming message no transaction"; "id" => in_msg.id); // %%%
363369
}
364370
Ok(())
365371
}

tests/e2e/inmsgstest.go

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
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+
2546
func 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

Comments
 (0)