Skip to content

Commit

Permalink
chore(dot/rpc): Load test submit extrinsic (#2089)
Browse files Browse the repository at this point in the history
* Load test submit extrinsic
  • Loading branch information
arijitAD authored Dec 1, 2021
1 parent 2e57d15 commit 8c58282
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/stress/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,75 @@ func Test_SubmitAndWatchExtrinsic(t *testing.T) {
`"method":"author_extrinsicUpdate","params":{"result":{"inBlock":"`)

}

func TestSync_SubmitExtrinsicLoad(t *testing.T) {
t.Skip()

// Instantiate the API
// send tx to non-authority node
api, err := gsrpc.NewSubstrateAPI(fmt.Sprintf("ws://localhost:%s", "8546"))
require.NoError(t, err)

meta, err := api.RPC.State.GetMetadataLatest()
require.NoError(t, err)

// Create a call, transferring 12345 units to Bob
bob, err := types.NewMultiAddressFromHexAccountID("0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48")
require.NoError(t, err)

// 1 unit of transfer
bal, ok := new(big.Int).SetString("1000", 10)
require.True(t, ok, "failed to convert balance")

c, err := types.NewCall(meta, "Balances.transfer", bob, types.NewUCompact(bal))
require.NoError(t, err)

// Create the extrinsic
ext := types.NewExtrinsic(c)

genesisHash, err := api.RPC.Chain.GetBlockHash(0)
require.NoError(t, err)

rv, err := api.RPC.State.GetRuntimeVersionLatest()
require.NoError(t, err)

alice := signature.TestKeyringPairAlice.PublicKey
key, err := types.CreateStorageKey(meta, "System", "Account", alice)
require.NoError(t, err)

var accountInfo types.AccountInfo
ok, err = api.RPC.State.GetStorageLatest(key, &accountInfo)
require.NoError(t, err)
require.True(t, ok)

previous := accountInfo.Data.Free
t.Logf("%#x has a balance of %v\n", alice, previous)
t.Logf("You may leave this example running and transfer any value to %#x\n", alice)

nonce := uint32(accountInfo.Nonce)
for i := 0; i < 1000; i++ {
t.Logf("nonce: %v", nonce)
o := types.SignatureOptions{
BlockHash: genesisHash,
Era: types.ExtrinsicEra{IsMortalEra: false},
GenesisHash: genesisHash,
Nonce: types.NewUCompactFromUInt(uint64(nonce)),
SpecVersion: rv.SpecVersion,
Tip: types.NewUCompactFromUInt(0),
TransactionVersion: rv.TransactionVersion,
}

nonce++
// Sign the transaction using Alice's default account
err = ext.Sign(signature.TestKeyringPairAlice, o)
require.NoError(t, err)

// Send the extrinsic
hash, err := api.RPC.Author.SubmitExtrinsic(ext)
require.NoError(t, err)
require.NotEqual(t, types.Hash{}, hash)

t.Logf("Balance transferred from Alice to Bob: %v\n", bal.String())
// Output: Balance transferred from Alice to Bob: 100000000000000
}
}

0 comments on commit 8c58282

Please sign in to comment.