Skip to content

Commit

Permalink
add test for apply extrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmack committed Mar 3, 2021
1 parent 276e61b commit b03cde1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dot/rpc/modules/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fmt.Printf("SubExt ext %v\n", extBytes)
return err
}

vtx := transaction.NewValidTransaction(ext, txv)
vtx := transaction.NewValidTransaction(extBytes, txv)

if cm.coreAPI.IsBlockProducer() {
hash := cm.txStateAPI.AddToPool(vtx)
Expand All @@ -190,7 +190,7 @@ fmt.Printf("SubExt ext %v\n", extBytes)
}

//broadcast
err = cm.coreAPI.HandleSubmittedExtrinsic(ext)
err = cm.coreAPI.HandleSubmittedExtrinsic(extBytes)
if err != nil {
cm.logger.Trace("failed to submit extrinsic to network", "error", err)
}
Expand Down
4 changes: 3 additions & 1 deletion dot/rpc/modules/author_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package modules

import (
"fmt"
"github.com/ChainSafe/gossamer/lib/common"
"os"
"reflect"
"testing"
Expand All @@ -20,7 +21,8 @@ import (
)

// https://github.com/paritytech/substrate/blob/5420de3face1349a97eb954ae71c5b0b940c31de/core/transaction-pool/src/tests.rs#L95
var testExt = []byte{1, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 142, 175, 4, 21, 22, 135, 115, 99, 38, 201, 254, 161, 126, 37, 252, 82, 135, 97, 54, 147, 201, 18, 144, 156, 178, 38, 170, 71, 148, 242, 106, 72, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 216, 5, 113, 87, 87, 40, 221, 120, 247, 252, 137, 201, 74, 231, 222, 101, 85, 108, 102, 39, 31, 190, 210, 14, 215, 124, 19, 160, 180, 203, 54, 110, 167, 163, 149, 45, 12, 108, 80, 221, 65, 238, 57, 237, 199, 16, 10, 33, 185, 8, 244, 184, 243, 139, 5, 87, 252, 245, 24, 225, 37, 154, 163, 142}
//var testExt = []byte{1, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, 142, 175, 4, 21, 22, 135, 115, 99, 38, 201, 254, 161, 126, 37, 252, 82, 135, 97, 54, 147, 201, 18, 144, 156, 178, 38, 170, 71, 148, 242, 106, 72, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 216, 5, 113, 87, 87, 40, 221, 120, 247, 252, 137, 201, 74, 231, 222, 101, 85, 108, 102, 39, 31, 190, 210, 14, 215, 124, 19, 160, 180, 203, 54, 110, 167, 163, 149, 45, 12, 108, 80, 221, 65, 238, 57, 237, 199, 16, 10, 33, 185, 8, 244, 184, 243, 139, 5, 87, 252, 245, 24, 225, 37, 154, 163, 142}
var testExt = common.MustHexToBytes("0x410284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01f8efbe48487e57a22abf7e3acd491b7f3528a33a111b1298601554863d27eb129eaa4e718e1365414ff3d028b62bebc651194c6b5001e5c2839b982757e08a8c0000000600ff8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480b00c465f14670")

// invalid transaction (above tx, with last byte changed)
//nolint
Expand Down
32 changes: 32 additions & 0 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wasmer
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"testing"
Expand Down Expand Up @@ -435,6 +436,37 @@ func TestInstance_ExecuteBlock_GossamerRuntime(t *testing.T) {
require.NoError(t, err)
}

func TestInstance_ApplyExtrinsic_GossamerRuntime(t *testing.T) {
gen, err := genesis.NewGenesisFromJSONRaw("../../../chain/gssmr/genesis-raw.json")
require.NoError(t, err)

genTrie, err := genesis.NewTrieFromGenesis(gen)
require.NoError(t, err)

// set state to genesis state
genState, err := storage.NewTrieState(genTrie)
require.NoError(t, err)

cfg := &Config{}
cfg.Storage = genState
cfg.LogLvl = 4

instance, err := NewRuntimeFromGenesis(gen, cfg)
require.NoError(t, err)

// reset state back to parent state before executing
parentState, err := storage.NewTrieState(genTrie)
require.NoError(t, err)
instance.SetContextStorage(parentState)

ext := types.Extrinsic(common.MustHexToBytes("0x310284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0158b82d5298c0beafd24c2e856d7424cd58aad308a6a09d168ffe16b217d4122d9dbbccf258fd63b48c36c1a6a2f20d11c6c3ab424a981931fe38e0f372b5fb8da60000000600ff90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22e5c0"))

res, err := instance.ApplyExtrinsic(ext)
// todo (ed) determine how to handle this result
fmt.Printf("result %v\n", res)
require.NoError(t, err)
}

func TestInstance_ExecuteBlock_PolkadotRuntime(t *testing.T) {
DefaultTestLogLvl = 0

Expand Down
4 changes: 3 additions & 1 deletion tests/rpc/rpc_02-author_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ func TestAuthorSubmitExtrinsic(t *testing.T) {
func TestDecodeExt(t *testing.T) {
buffer := bytes.Buffer{}
decoder := scale.NewDecoder(&buffer)
buffer.Write(common.MustHexToBytes("0x2d0284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d015212790fabe9d6ca21948e82767f38a5ee8645b1426b8ef4a678299852dcfa694b8388b1aa76e9b34eeccaa023c5ff2d7207763fbf9eb5dd01b1617adb7350820000000600ff90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22e5c0"))
buffer.Write(common.MustHexToBytes("0x410284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01f8efbe48487e57a22abf7e3acd491b7f3528a33a111b1298601554863d27eb129eaa4e718e1365414ff3d028b62bebc651194c6b5001e5c2839b982757e08a8c0000000600ff8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480b00c465f14670"))
//buffer.Write(common.MustHexToBytes("0x2d0284ffd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d015212790fabe9d6ca21948e82767f38a5ee8645b1426b8ef4a678299852dcfa694b8388b1aa76e9b34eeccaa023c5ff2d7207763fbf9eb5dd01b1617adb7350820000000600ff90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22e5c0"))
ext := types.Extrinsic{}
err := decoder.Decode(&ext)
require.NoError(t, err)
fmt.Printf("decoded ext %+v\n", ext)

}

func TestAuthorRPC(t *testing.T) {
Expand Down

0 comments on commit b03cde1

Please sign in to comment.