Skip to content

Commit

Permalink
feat: remove deprecated script
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Oct 21, 2024
1 parent b6f4df4 commit 2c88c23
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 405 deletions.
47 changes: 0 additions & 47 deletions dot/rpc/modules/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/pkg/scale"
"github.com/ChainSafe/gossamer/pkg/trie"
)

// StateGetReadProofRequest json fields
Expand Down Expand Up @@ -83,10 +82,6 @@ type StateStorageQueryAtRequest struct {
At common.Hash `json:"at"`
}

type StateTrieAtRequest struct {
At *common.Hash `json:"at"`
}

// StateStorageKeysQuery field to store storage keys
type StateStorageKeysQuery [][]byte

Expand Down Expand Up @@ -117,8 +112,6 @@ type StateStorageResponse string
// StatePairResponse is a key values
type StatePairResponse []interface{}

type StateTrieResponse []string

// StateStorageKeysResponse field for storage keys
type StateStorageKeysResponse []string

Expand Down Expand Up @@ -252,46 +245,6 @@ func (sm *StateModule) GetPairs(_ *http.Request, req *StatePairRequest, res *Sta
return nil
}

// Trie RPC method returns a list of scale encoded trie.Entry{Key byte, Value byte} representing
// all the entries in a trie for a block hash, if no block hash is given then it uses the best block hash
func (sm *StateModule) Trie(_ *http.Request, req *StateTrieAtRequest, res *StateTrieResponse) error {
var blockHash common.Hash

if req.At != nil {
blockHash = *req.At
} else {
blockHash = sm.blockAPI.BestBlockHash()
}

blockHeader, err := sm.blockAPI.GetHeader(blockHash)
if err != nil {
return fmt.Errorf("getting header: %w", err)
}

entries, err := sm.storageAPI.Entries(&blockHeader.StateRoot)
if err != nil {
return fmt.Errorf("getting entries: %w", err)
}

entriesArr := make([]string, 0, len(entries))
for key, value := range entries {
entry := trie.Entry{
Key: []byte(key),
Value: value,
}

encodedEntry, err := scale.Marshal(entry)
if err != nil {
return fmt.Errorf("scale encoding entry: %w", err)
}

entriesArr = append(entriesArr, common.BytesToHex(encodedEntry))
}

*res = entriesArr
return nil
}

// Call makes a call to the runtime.
func (sm *StateModule) Call(_ *http.Request, req *StateCallRequest, res *StateCallResponse) error {
var blockHash common.Hash
Expand Down
93 changes: 0 additions & 93 deletions dot/rpc/modules/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ package modules
import (
"errors"
"net/http"
"slices"
"testing"

wazero_runtime "github.com/ChainSafe/gossamer/lib/runtime/wazero"
"github.com/ChainSafe/gossamer/pkg/trie"

"github.com/ChainSafe/gossamer/dot/rpc/modules/mocks"
testdata "github.com/ChainSafe/gossamer/dot/rpc/modules/test_data"
Expand All @@ -32,7 +30,6 @@ import (
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/pkg/scale"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

Expand Down Expand Up @@ -311,96 +308,6 @@ func TestCall(t *testing.T) {
assert.NotEmpty(t, res)
}

func TestStateTrie(t *testing.T) {
expecificBlockHash := common.Hash([32]byte{6, 6, 6, 6, 6, 6})
var expectedEncodedSlice []string
entries := []trie.Entry{
{Key: []byte("entry-1"), Value: []byte{0, 1, 2, 3}},
{Key: []byte("entry-2"), Value: []byte{3, 4, 5, 6}},
}

for _, entry := range entries {
expectedEncodedSlice = append(expectedEncodedSlice, common.BytesToHex(scale.MustMarshal(entry)))
}

testcases := map[string]struct {
request StateTrieAtRequest
newStateModule func(t *testing.T) *StateModule
expected StateTrieResponse
}{
"blockhash_parameter_nil": {
request: StateTrieAtRequest{At: nil},
expected: expectedEncodedSlice,
newStateModule: func(t *testing.T) *StateModule {
ctrl := gomock.NewController(t)

bestBlockHash := common.Hash([32]byte{1, 0, 1, 0, 1})
blockAPIMock := NewMockBlockAPI(ctrl)
blockAPIMock.EXPECT().BestBlockHash().Return(bestBlockHash)

fakeStateRoot := common.Hash([32]byte{5, 5, 5, 5, 5})
fakeBlockHeader := types.NewHeader(common.EmptyHash, fakeStateRoot,
common.EmptyHash, 1, nil)

blockAPIMock.EXPECT().GetHeader(bestBlockHash).Return(fakeBlockHeader, nil)

fakeEntries := map[string][]byte{
"entry-1": {0, 1, 2, 3},
"entry-2": {3, 4, 5, 6},
}
storageAPIMock := NewMockStorageAPI(ctrl)
storageAPIMock.EXPECT().Entries(&fakeStateRoot).
Return(fakeEntries, nil)

sm := NewStateModule(nil, storageAPIMock, nil, blockAPIMock)
return sm
},
},
"blockhash_parameter_not_nil": {
request: StateTrieAtRequest{At: &expecificBlockHash},
expected: expectedEncodedSlice,
newStateModule: func(t *testing.T) *StateModule {
ctrl := gomock.NewController(t)
blockAPIMock := NewMockBlockAPI(ctrl)

fakeStateRoot := common.Hash([32]byte{5, 5, 5, 5, 5})
fakeBlockHeader := types.NewHeader(common.EmptyHash, fakeStateRoot,
common.EmptyHash, 1, nil)

blockAPIMock.EXPECT().GetHeader(expecificBlockHash).
Return(fakeBlockHeader, nil)

fakeEntries := map[string][]byte{
"entry-1": {0, 1, 2, 3},
"entry-2": {3, 4, 5, 6},
}
storageAPIMock := NewMockStorageAPI(ctrl)
storageAPIMock.EXPECT().Entries(&fakeStateRoot).
Return(fakeEntries, nil)

sm := NewStateModule(nil, storageAPIMock, nil, blockAPIMock)
return sm
},
},
}

for tname, tt := range testcases {
tt := tt

t.Run(tname, func(t *testing.T) {
sm := tt.newStateModule(t)

var res StateTrieResponse
err := sm.Trie(nil, &tt.request, &res)
require.NoError(t, err)

slices.Sort(tt.expected)
slices.Sort(res)
require.Equal(t, tt.expected, res)
})
}
}

func TestStateModuleGetMetadata(t *testing.T) {
ctrl := gomock.NewController(t)

Expand Down
139 changes: 0 additions & 139 deletions scripts/trie_state/trie_state_script.go

This file was deleted.

Loading

0 comments on commit 2c88c23

Please sign in to comment.