Implement getSlice
API
#206
@ -19,6 +19,7 @@ package eth_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
@ -44,6 +45,21 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
parsedABI abi.ABI
|
parsedABI abi.ABI
|
||||||
|
|
||||||
|
stateRoot = common.HexToHash("0x572ef3b6b3d5164ed9d83341073f13af4d60a3aab38989b6c03917544f186a43")
|
||||||
|
rootDataHash = "572ef3b6b3d5164ed9d83341073f13af4d60a3aab38989b6c03917544f186a43"
|
||||||
|
rootData = "f8b1a0408dd81f6cd5c614f91ecd9faa01d5feba936e0314ba04f99c74069ba819e0f280808080a0b356351d60bc9894cf1f1d6cb68c815f0131d50f1da83c4023a09ec855cfff91a0180d554b171f6acf8295e376266df2311f68975d74c02753b85707d308f703e48080808080a0422c7cc4fa407603f0879a0ecaa809682ce98dbef30551a34bcce09fa3ac995180a02d264f591aa3fa9df3cbeea190a4fd8d5483ddfb1b85603b2a006d179f79ba358080"
|
||||||
|
|
||||||
|
account1DataHash = "180d554b171f6acf8295e376266df2311f68975d74c02753b85707d308f703e4"
|
||||||
|
account1Data = "f869a03114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45b846f8440180a04bd45c41d863f1bcf5da53364387fcdd64f77924d388a4df47e64132273fb4c0a0ba79854f3dbf6505fdbb085888e25fae8fa97288c5ce8fcd39aa589290d9a659"
|
||||||
|
account2DataHash = "2d264f591aa3fa9df3cbeea190a4fd8d5483ddfb1b85603b2a006d179f79ba35"
|
||||||
|
account2Data = "f871a03926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2b84ef84c02881bc16d674ec82710a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
||||||
|
account3DataHash = "408dd81f6cd5c614f91ecd9faa01d5feba936e0314ba04f99c74069ba819e0f2"
|
||||||
|
account3Data = "f86da030bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2ab84af848058405f5b608a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
||||||
|
account4DataHash = "422c7cc4fa407603f0879a0ecaa809682ce98dbef30551a34bcce09fa3ac9951"
|
||||||
|
account4Data = "f871a03957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45b84ef84c80883782dace9d9003e8a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
||||||
|
account5DataHash = "b356351d60bc9894cf1f1d6cb68c815f0131d50f1da83c4023a09ec855cfff91"
|
||||||
|
account5Data = "f871a03380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312ab84ef84c80883782dace9d900000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -529,4 +545,45 @@ var _ = Describe("eth state reading tests", func() {
|
|||||||
Expect(header).To(Equal(expectedCanonicalHeader))
|
Expect(header).To(Equal(expectedCanonicalHeader))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Describe("eth_getSlice", func() {
|
||||||
|
It("Retrieves the state nodes for root path", func() {
|
||||||
|
path := "0x"
|
||||||
|
depth := 3
|
||||||
|
sliceResponse, err := api.GetSlice(ctx, "0x", 3, stateRoot, false)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
expectedResponse := eth.GetSliceResponse{
|
||||||
|
SliceID: fmt.Sprintf("%s-%d-%s", path, depth, stateRoot.String()),
|
||||||
|
MetaData: eth.GetSliceResponseMetadata{
|
||||||
|
NodeStats: map[string]string{
|
||||||
|
"00-stem-and-head-nodes": "1",
|
||||||
|
"01-max-depth": "1",
|
||||||
|
"02-total-trie-nodes": "6",
|
||||||
|
"03-leaves": "5",
|
||||||
|
"04-smart-contracts": "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TrieNodes: eth.GetSliceResponseTrieNodes{
|
||||||
|
Stem: map[string]string{},
|
||||||
|
Head: map[string]string{
|
||||||
|
rootDataHash: rootData,
|
||||||
|
},
|
||||||
|
Slice: map[string]string{
|
||||||
|
account1DataHash: account1Data,
|
||||||
|
account2DataHash: account2Data,
|
||||||
|
account3DataHash: account3Data,
|
||||||
|
account4DataHash: account4Data,
|
||||||
|
account5DataHash: account5Data,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Leaves: map[string]eth.GetSliceResponseAccount{},
|
||||||
|
}
|
||||||
|
|
||||||
|
Expect(sliceResponse.SliceID).To(Equal(expectedResponse.SliceID))
|
||||||
|
Expect(sliceResponse.MetaData.NodeStats).To(Equal(expectedResponse.MetaData.NodeStats))
|
||||||
|
Expect(sliceResponse.TrieNodes).To(Equal(expectedResponse.TrieNodes))
|
||||||
|
Expect(sliceResponse.Leaves).To(Equal(expectedResponse.Leaves))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -290,7 +290,7 @@ func (sr *GetSliceResponse) init(path string, depth int, root common.Hash) {
|
|||||||
|
|
||||||
type GetSliceResponseMetadata struct {
|
type GetSliceResponseMetadata struct {
|
||||||
TimeStats map[string]string `json:"timeStats"` // stem, state, storage (one by one)
|
TimeStats map[string]string `json:"timeStats"` // stem, state, storage (one by one)
|
||||||
NodeStats map[string]string `json:"trieNodes"` // total, leaves, smart contracts
|
NodeStats map[string]string `json:"nodeStats"` // total, leaves, smart contracts
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetSliceResponseTrieNodes struct {
|
type GetSliceResponseTrieNodes struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user