Skip to content

Commit

Permalink
rebase. remove duplicate tests. docs
Browse files Browse the repository at this point in the history
  • Loading branch information
radkomih committed Apr 22, 2024
1 parent c18092b commit 798da16
Show file tree
Hide file tree
Showing 46 changed files with 258 additions and 3,406 deletions.
Binary file modified build/runtime.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions docs/docs/development/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Contains modules of the [Runtime API Specification](https://spec.polkadot.networ
|--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| [AccountNonceApi](https://github.com/limechain/gosemble/tree/develop/api/account_nonce) | Provides logic to get an account's nonce. |
| [AuraApi](https://github.com/limechain/gosemble/tree/develop/api/aura) | Manages block authoring AuRa consensus mechanism. |
| [BabeApi](https://github.com/limechain/gosemble/tree/develop/api/babe) | Manages block authoring BABE consensus mechanism. |
| [Benchmarking](https://github.com/limechain/gosemble/tree/develop/api/benchmarking) | Provides functionality for benchmarking extrinsic calls and system hooks. |
| [BlockBuilder](https://github.com/limechain/gosemble/tree/develop/api/block_builder) | Provides functionality for building and finalizing a block. |
| [Core](https://github.com/limechain/gosemble/tree/develop/api/core) | Provides functionality for initialising and executing a block. |
Expand Down
1 change: 1 addition & 0 deletions docs/docs/development/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ These modules provide features than can be useful for your blockchain and can be
| Name | Description |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
| [aura](https://github.com/limechain/gosemble/tree/develop/frame/aura) | Manages the AuRa (Authority Round) consensus mechanism. |
| [babe](https://github.com/limechain/gosemble/tree/develop/frame/babe) | Manages the BABE (Blind Assignment for Blockchain Extension) consensus mechanism. |
| [balances](https://github.com/limechain/gosemble/tree/develop/frame/balances) | Provides functionality for handling accounts and balances of native currency. |
| [grandpa](https://github.com/limechain/gosemble/tree/develop/frame/grandpa) | Manages the GRANDPA block finalization. |
| [session](https://github.com/limechain/gosemble/tree/develop/frame/session) | Allows validators to manage their session keys, handles session rotation. |
Expand Down
2 changes: 1 addition & 1 deletion gossamer
Submodule gossamer updated 1 files
+4 −4 dot/node.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package main

import (
"testing"

"github.com/LimeChain/gosemble/benchmarking"
"github.com/LimeChain/gosemble/primitives/types"
"github.com/LimeChain/gosemble/testhelpers"
"github.com/stretchr/testify/assert"
"testing"
)

func BenchmarkSudoSetKey(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/sudo/call_set_key_weight.go", func(i *benchmarking.Instance) {
err := (*i.Storage()).Put(append(keySudoHash, keyKeyHash...), aliceAddress.AsID.ToBytes())
err := (*i.Storage()).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), aliceAddress.AsID.ToBytes())
assert.NoError(b, err)

err = i.ExecuteExtrinsic(
Expand All @@ -19,6 +21,6 @@ func BenchmarkSudoSetKey(b *testing.B) {
)
assert.NoError(b, err)

assert.Equal(b, bobAddress.AsID.ToBytes(), (*i.Storage()).Get(append(keySudoHash, keyKeyHash...)))
assert.Equal(b, bobAddress.AsID.ToBytes(), (*i.Storage()).Get(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...)))
})
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package main

import (
"testing"

"github.com/LimeChain/gosemble/benchmarking"
"github.com/LimeChain/gosemble/primitives/types"
"github.com/LimeChain/gosemble/testhelpers"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/stretchr/testify/assert"
"testing"
)

func BenchmarkSudoSudoAs(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/sudo/call_sudo_as_weight.go", func(i *benchmarking.Instance) {
err := (*i.Storage()).Put(append(keySudoHash, keyKeyHash...), aliceAddress.AsID.ToBytes())
err := (*i.Storage()).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), aliceAddress.AsID.ToBytes())
assert.NoError(b, err)

call, err := ctypes.NewCall(i.Metadata(), "System.remark", []byte{})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package main

import (
"testing"

"github.com/LimeChain/gosemble/benchmarking"
"github.com/LimeChain/gosemble/primitives/types"
"github.com/LimeChain/gosemble/testhelpers"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/stretchr/testify/assert"
"testing"
)

func BenchmarkSudoSudo(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/sudo/call_sudo_weight.go", func(i *benchmarking.Instance) {
err := (*i.Storage()).Put(append(keySudoHash, keyKeyHash...), aliceAddress.AsID.ToBytes())
err := (*i.Storage()).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), aliceAddress.AsID.ToBytes())
assert.NoError(b, err)

call, err := ctypes.NewCall(i.Metadata(), "System.remark", []byte{})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package main

import (
"testing"

"github.com/LimeChain/gosemble/benchmarking"
"github.com/LimeChain/gosemble/primitives/types"
"github.com/LimeChain/gosemble/testhelpers"
"github.com/stretchr/testify/assert"
"testing"
)

func BenchmarkSudoRemoveKey(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/sudo/call_remove_key_weight.go", func(i *benchmarking.Instance) {
err := (*i.Storage()).Put(append(keySudoHash, keyKeyHash...), aliceAddress.AsID.ToBytes())
err := (*i.Storage()).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), aliceAddress.AsID.ToBytes())
assert.NoError(b, err)

err = i.ExecuteExtrinsic(
Expand All @@ -18,6 +20,6 @@ func BenchmarkSudoRemoveKey(b *testing.B) {
)
assert.NoError(b, err)

assert.Nil(b, (*i.Storage()).Get(append(keySudoHash, keyKeyHash...)))
assert.Nil(b, (*i.Storage()).Get(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...)))
})
}
2 changes: 1 addition & 1 deletion runtime/templates/poa/genesis_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ func Test_BuildConfig(t *testing.T) {
assert.Equal(t, expectedNextFeeMultiplier.Bytes(), nextFeeMultiplier)

// assert sudo key
assert.Equal(t, aliceAddress.AsID.ToBytes(), (*storage).Get(append(keySudoHash, keyKeyHash...)))
assert.Equal(t, aliceAddress.AsID.ToBytes(), (*storage).Get(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package main

import (
"bytes"
"math/big"
"testing"

"github.com/LimeChain/gosemble/testhelpers"
cscale "github.com/centrifuge/go-substrate-rpc-client/v4/scale"
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/stretchr/testify/assert"
"math/big"
"testing"
)

func Test_Sudo_RemoveKey_Success(t *testing.T) {
rt, storage := newTestRuntime(t)
metadata := runtimeMetadata(t, rt)
rt, storage := testhelpers.NewRuntimeInstance(t)
metadata := testhelpers.RuntimeMetadata(t, rt)

runtimeVersion, err := rt.Version()
assert.NoError(t, err)
Expand All @@ -21,11 +23,11 @@ func Test_Sudo_RemoveKey_Success(t *testing.T) {
balance, e := big.NewInt(0).SetString("50000000000000000", 10)
assert.True(t, e)

setStorageAccountInfo(t, storage, signature.TestKeyringPairAlice.PublicKey, balance, 0)
initializeBlock(t, rt, parentHash, stateRoot, extrinsicsRoot, blockNumber)
testhelpers.SetStorageAccountInfo(t, storage, signature.TestKeyringPairAlice.PublicKey, balance, 0)
testhelpers.InitializeBlock(t, rt, testhelpers.ParentHash, testhelpers.StateRoot, testhelpers.ExtrinsicsRoot, testhelpers.BlockNumber)

// Set Sudo Key
err = (*storage).Put(append(keySudoHash, keyKeyHash...), signature.TestKeyringPairAlice.PublicKey)
err = (*storage).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), signature.TestKeyringPairAlice.PublicKey)
assert.NoError(t, err)

call, err := ctypes.NewCall(metadata, "Sudo.remove_key")
Expand All @@ -34,9 +36,9 @@ func Test_Sudo_RemoveKey_Success(t *testing.T) {
extrinsic := ctypes.NewExtrinsic(call)

o := ctypes.SignatureOptions{
BlockHash: ctypes.Hash(parentHash),
BlockHash: ctypes.Hash(testhelpers.ParentHash),
Era: ctypes.ExtrinsicEra{IsImmortalEra: true},
GenesisHash: ctypes.Hash(parentHash),
GenesisHash: ctypes.Hash(testhelpers.ParentHash),
Nonce: ctypes.NewUCompactFromUInt(0),
SpecVersion: ctypes.U32(runtimeVersion.SpecVersion),
Tip: ctypes.NewUCompactFromUInt(0),
Expand All @@ -54,13 +56,13 @@ func Test_Sudo_RemoveKey_Success(t *testing.T) {
res, err := rt.Exec("BlockBuilder_apply_extrinsic", extEnc.Bytes())
assert.NoError(t, err)

assert.Equal(t, applyExtrinsicResultOutcome.Bytes(), res)
assert.Nil(t, (*storage).Get(append(keySudoHash, keyKeyHash...)))
assert.Equal(t, testhelpers.ApplyExtrinsicResultOutcome.Bytes(), res)
assert.Nil(t, (*storage).Get(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...)))
}

func Test_Sudo_RemoveKey_RequireSudo_EmptyKey(t *testing.T) {
rt, storage := newTestRuntime(t)
metadata := runtimeMetadata(t, rt)
rt, storage := testhelpers.NewRuntimeInstance(t)
metadata := testhelpers.RuntimeMetadata(t, rt)

runtimeVersion, err := rt.Version()
assert.NoError(t, err)
Expand All @@ -69,18 +71,18 @@ func Test_Sudo_RemoveKey_RequireSudo_EmptyKey(t *testing.T) {
balance, e := big.NewInt(0).SetString("50000000000000000", 10)
assert.True(t, e)

setStorageAccountInfo(t, storage, signature.TestKeyringPairAlice.PublicKey, balance, 0)
initializeBlock(t, rt, parentHash, stateRoot, extrinsicsRoot, blockNumber)
testhelpers.SetStorageAccountInfo(t, storage, signature.TestKeyringPairAlice.PublicKey, balance, 0)
testhelpers.InitializeBlock(t, rt, testhelpers.ParentHash, testhelpers.StateRoot, testhelpers.ExtrinsicsRoot, testhelpers.BlockNumber)

call, err := ctypes.NewCall(metadata, "Sudo.remove_key")
assert.NoError(t, err)

extrinsic := ctypes.NewExtrinsic(call)

o := ctypes.SignatureOptions{
BlockHash: ctypes.Hash(parentHash),
BlockHash: ctypes.Hash(testhelpers.ParentHash),
Era: ctypes.ExtrinsicEra{IsImmortalEra: true},
GenesisHash: ctypes.Hash(parentHash),
GenesisHash: ctypes.Hash(testhelpers.ParentHash),
Nonce: ctypes.NewUCompactFromUInt(0),
SpecVersion: ctypes.U32(runtimeVersion.SpecVersion),
Tip: ctypes.NewUCompactFromUInt(0),
Expand All @@ -98,5 +100,5 @@ func Test_Sudo_RemoveKey_RequireSudo_EmptyKey(t *testing.T) {
res, err := rt.Exec("BlockBuilder_apply_extrinsic", extEnc.Bytes())
assert.NoError(t, err)

assert.Equal(t, applyExtrinsicResultSudoRequireSudoErr.Bytes(), res)
assert.Equal(t, testhelpers.ApplyExtrinsicResultSudoRequireSudoErr.Bytes(), res)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package main

import (
"bytes"
"math/big"
"testing"

"github.com/LimeChain/gosemble/testhelpers"
cscale "github.com/centrifuge/go-substrate-rpc-client/v4/scale"
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/stretchr/testify/assert"
"math/big"
"testing"
)

func Test_Sudo_SetKey_Success(t *testing.T) {
rt, storage := newTestRuntime(t)
metadata := runtimeMetadata(t, rt)
rt, storage := testhelpers.NewRuntimeInstance(t)
metadata := testhelpers.RuntimeMetadata(t, rt)

runtimeVersion, err := rt.Version()
assert.NoError(t, err)
Expand All @@ -21,15 +23,15 @@ func Test_Sudo_SetKey_Success(t *testing.T) {
balance, e := big.NewInt(0).SetString("50000000000000000", 10)
assert.True(t, e)

setStorageAccountInfo(t, storage, signature.TestKeyringPairAlice.PublicKey, balance, 0)
initializeBlock(t, rt, parentHash, stateRoot, extrinsicsRoot, blockNumber)
testhelpers.SetStorageAccountInfo(t, storage, signature.TestKeyringPairAlice.PublicKey, balance, 0)
testhelpers.InitializeBlock(t, rt, testhelpers.ParentHash, testhelpers.StateRoot, testhelpers.ExtrinsicsRoot, testhelpers.BlockNumber)

bob, err := ctypes.NewMultiAddressFromHexAccountID(
"0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22")
assert.NoError(t, err)

// Set Sudo Key
err = (*storage).Put(append(keySudoHash, keyKeyHash...), signature.TestKeyringPairAlice.PublicKey)
err = (*storage).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), signature.TestKeyringPairAlice.PublicKey)
assert.NoError(t, err)

call, err := ctypes.NewCall(metadata, "Sudo.set_key", bob)
Expand All @@ -38,9 +40,9 @@ func Test_Sudo_SetKey_Success(t *testing.T) {
extrinsic := ctypes.NewExtrinsic(call)

o := ctypes.SignatureOptions{
BlockHash: ctypes.Hash(parentHash),
BlockHash: ctypes.Hash(testhelpers.ParentHash),
Era: ctypes.ExtrinsicEra{IsImmortalEra: true},
GenesisHash: ctypes.Hash(parentHash),
GenesisHash: ctypes.Hash(testhelpers.ParentHash),
Nonce: ctypes.NewUCompactFromUInt(0),
SpecVersion: ctypes.U32(runtimeVersion.SpecVersion),
Tip: ctypes.NewUCompactFromUInt(0),
Expand All @@ -58,13 +60,13 @@ func Test_Sudo_SetKey_Success(t *testing.T) {
res, err := rt.Exec("BlockBuilder_apply_extrinsic", extEnc.Bytes())
assert.NoError(t, err)

assert.Equal(t, applyExtrinsicResultOutcome.Bytes(), res)
assert.Equal(t, bob.AsID.ToBytes(), (*storage).Get(append(keySudoHash, keyKeyHash...)))
assert.Equal(t, testhelpers.ApplyExtrinsicResultOutcome.Bytes(), res)
assert.Equal(t, bob.AsID.ToBytes(), (*storage).Get(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...)))
}

func Test_Sudo_SetKey_RequireSudo(t *testing.T) {
rt, storage := newTestRuntime(t)
metadata := runtimeMetadata(t, rt)
rt, storage := testhelpers.NewRuntimeInstance(t)
metadata := testhelpers.RuntimeMetadata(t, rt)

runtimeVersion, err := rt.Version()
assert.NoError(t, err)
Expand All @@ -73,15 +75,15 @@ func Test_Sudo_SetKey_RequireSudo(t *testing.T) {
balance, e := big.NewInt(0).SetString("50000000000000000", 10)
assert.True(t, e)

setStorageAccountInfo(t, storage, signature.TestKeyringPairAlice.PublicKey, balance, 0)
initializeBlock(t, rt, parentHash, stateRoot, extrinsicsRoot, blockNumber)
testhelpers.SetStorageAccountInfo(t, storage, signature.TestKeyringPairAlice.PublicKey, balance, 0)
testhelpers.InitializeBlock(t, rt, testhelpers.ParentHash, testhelpers.StateRoot, testhelpers.ExtrinsicsRoot, testhelpers.BlockNumber)

bob, err := ctypes.NewMultiAddressFromHexAccountID(
"0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22")
assert.NoError(t, err)

// Set bob Sudo Key
err = (*storage).Put(append(keySudoHash, keyKeyHash...), bob.AsID.ToBytes())
err = (*storage).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), bob.AsID.ToBytes())
assert.NoError(t, err)

call, err := ctypes.NewCall(metadata, "Sudo.set_key", bob)
Expand All @@ -90,9 +92,9 @@ func Test_Sudo_SetKey_RequireSudo(t *testing.T) {
extrinsic := ctypes.NewExtrinsic(call)

o := ctypes.SignatureOptions{
BlockHash: ctypes.Hash(parentHash),
BlockHash: ctypes.Hash(testhelpers.ParentHash),
Era: ctypes.ExtrinsicEra{IsImmortalEra: true},
GenesisHash: ctypes.Hash(parentHash),
GenesisHash: ctypes.Hash(testhelpers.ParentHash),
Nonce: ctypes.NewUCompactFromUInt(0),
SpecVersion: ctypes.U32(runtimeVersion.SpecVersion),
Tip: ctypes.NewUCompactFromUInt(0),
Expand All @@ -110,6 +112,6 @@ func Test_Sudo_SetKey_RequireSudo(t *testing.T) {
res, err := rt.Exec("BlockBuilder_apply_extrinsic", extEnc.Bytes())
assert.NoError(t, err)

assert.Equal(t, applyExtrinsicResultSudoRequireSudoErr.Bytes(), res)
assert.Equal(t, bob.AsID.ToBytes(), (*storage).Get(append(keySudoHash, keyKeyHash...)))
assert.Equal(t, testhelpers.ApplyExtrinsicResultSudoRequireSudoErr.Bytes(), res)
assert.Equal(t, bob.AsID.ToBytes(), (*storage).Get(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...)))
}
Loading

0 comments on commit 798da16

Please sign in to comment.