Skip to content

Commit

Permalink
floating, insufficient balance
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Mar 25, 2022
1 parent 41110cb commit 1e64608
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
8 changes: 7 additions & 1 deletion runtime-sdk/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ impl<R: Runtime> Dispatcher<R> {
data: &IncomingMessageData,
tx: &Option<Transaction>,
) -> Result<(), RuntimeError> {
warn!(ctx.get_logger("dispatcher"), "incoming message executing"; "id" => in_msg.id); // %%%
R::Modules::execute_in_msg(ctx, in_msg, data, tx)?;
warn!(ctx.get_logger("dispatcher"), "incoming message modules done"; "id" => in_msg.id); // %%%
if let Some(tx) = tx {
let tx_size = match data
.ut
Expand All @@ -359,7 +361,11 @@ impl<R: Runtime> Dispatcher<R> {
};
// Use the ID as index.
let index = in_msg.id.try_into().unwrap();
Self::execute_tx(ctx, tx_size, tx.clone(), index)?;
let result = Self::execute_tx(ctx, tx_size, tx.clone(), index)?;
let result_parsed = cbor::from_slice::<crate::types::transaction::CallResult>(&result.output).unwrap();
warn!(ctx.get_logger("dispatcher"), "incoming message transaction done"; "id" => in_msg.id, "result_parsed" => ?result_parsed); // %%%
} else {
warn!(ctx.get_logger("dispatcher"), "incoming message no transaction"; "id" => in_msg.id); // %%%
}
Ok(())
}
Expand Down
63 changes: 44 additions & 19 deletions tests/e2e/inmsgstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"time"

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

"github.com/oasisprotocol/oasis-core/go/common/cbor"
Expand All @@ -22,6 +21,28 @@ import (
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
)

func makeMintCheck(owner 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.Mint == nil {
return false
}
if !ae.Mint.Owner.Equal(owner) {
return false
}
if ae.Mint.Amount.Amount.Cmp(&amount.Amount) != 0 {
return false
}
if ae.Mint.Amount.Denomination != amount.Denomination {
return false
}
return true
}
}

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)
Expand Down Expand Up @@ -70,15 +91,24 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C

runtimeAddr := staking.NewRuntimeAddress(runtimeID)

log.Warn("0: get alice starting balance")
aliceAccount, err := cons.Staking().Account(ctx, &staking.OwnerQuery{
Height: consensus.HeightLatest,
Owner: testing.Alice.Address.ConsensusAddress(),
})
aliceExpectedBalance := aliceAccount.General.Balance

// Message with transfer.
transferAmount := types.NewBaseUnits(*quantity.NewFromUint64(10_000), consDenomination)
transferAmount := types.NewBaseUnits(*quantity.NewFromUint64(100_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{
signedTx, err := transaction.Sign(testing.Alice.ConsensusSigner, roothash.NewSubmitMsgTx(0, &transaction.Fee{
Gas: 2000,
}, &roothash.SubmitMsg{
ID: runtimeID,
Tag: 0,
Fee: *quantity.NewFromUint64(1),
Expand All @@ -91,29 +121,24 @@ func IncomingMessagesTest(sc *RuntimeScenario, log *logging.Logger, conn *grpc.C
if err != nil {
return fmt.Errorf("msg 1 submit sign: %w", err)
}

theirChainContext, err := cons.GetChainContext(ctx)
if err != nil {
return err
}
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{
if err = aliceExpectedBalance.Sub(quantity.NewFromUint64(11)); err != nil {
return fmt.Errorf("msg 1 decreasing expected balance: %w", err)
}

log.Warn("1: alice get balance")
aliceAccount, err = cons.Staking().Account(ctx, &staking.OwnerQuery{
Height: consensus.HeightLatest,
Owner: testing.Alice.Address.ConsensusAddress(),
})
// todo: figure out what consensus balance should be. 1 million minus something from previous tests
expectedBalance := quantity.NewFromUint64(89)
if aliceAccount.General.Balance.Cmp(expectedBalance) != 0 {
return fmt.Errorf("after message 1: alice consensus balance expected %v actual %v", expectedBalance, aliceAccount.General.Balance)
if aliceAccount.General.Balance.Cmp(&aliceExpectedBalance) != 0 {
return fmt.Errorf("after message 1: alice consensus balance expected %v actual %v", aliceExpectedBalance, aliceAccount.General.Balance)
}
if err = ensureRuntimeEvent(log, acCh, makeMintCheck(testing.Alice.Address, transferAmount)); err != nil {
return fmt.Errorf("after msg 1 wait for mint event: %w", err)
}
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)
Expand Down

0 comments on commit 1e64608

Please sign in to comment.