Add test for missing canonical block

This commit is contained in:
nabarun 2022-06-16 19:10:28 +05:30
parent c666ece1df
commit 9e0717f3b3
2 changed files with 76 additions and 9 deletions

View File

@ -351,6 +351,65 @@ var NonCanonicalChainFromBlock2 = []Block{
}, },
} }
var chainUptoBlock1 = []Block{}
var _ = copy(chainUptoBlock1, InPlaceSnapshotBlocks[:2])
var ChainWithMissingBlock = append(
chainUptoBlock1,
// Missing block 2 where contract Test2 is deployed.
Block{
Hash: common.HexToHash("0x9fc4aaaab26f0b43ac609c99ae50925e5dc9a25f103c0511fcff38c6b3158302"),
Number: big.NewInt(3),
StateNodes: []snapt.Node{
// Branch root node.
{
NodeType: 0,
Path: []byte{},
Value: []byte{248, 113, 128, 128, 128, 128, 128, 128, 160, 70, 53, 190, 199, 124, 254, 86, 213, 42, 126, 117, 155, 2, 223, 56, 167, 130, 118, 10, 150, 65, 46, 207, 169, 167, 250, 209, 64, 37, 205, 153, 51, 128, 128, 160, 144, 157, 233, 94, 167, 75, 58, 117, 108, 223, 131, 243, 252, 66, 113, 189, 191, 20, 107, 203, 6, 36, 81, 190, 238, 197, 245, 57, 168, 66, 55, 114, 160, 203, 133, 96, 97, 241, 213, 137, 166, 12, 128, 197, 106, 1, 219, 6, 35, 173, 229, 112, 207, 13, 218, 225, 196, 121, 57, 204, 58, 107, 208, 227, 22, 128, 128, 128, 128, 128, 128},
},
// State node for sender account.
{
NodeType: 2,
Path: []byte{6},
Key: common.HexToHash("0x67ab3c0dd775f448af7fb41243415ed6fb975d1530a2d828f69bea7346231ad7"),
Value: []byte{248, 118, 160, 55, 171, 60, 13, 215, 117, 244, 72, 175, 127, 180, 18, 67, 65, 94, 214, 251, 151, 93, 21, 48, 162, 216, 40, 246, 155, 234, 115, 70, 35, 26, 215, 184, 83, 248, 81, 3, 141, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112},
},
// State node for contract Test1 transaction.
{
NodeType: 2,
Path: []byte{9},
Key: common.HexToHash("0x9397e33dedda4763aea143fc6151ebcd9a93f62db7a6a556d46c585d82ad2afc"),
Value: []byte{248, 105, 160, 51, 151, 227, 61, 237, 218, 71, 99, 174, 161, 67, 252, 97, 81, 235, 205, 154, 147, 246, 45, 183, 166, 165, 86, 212, 108, 88, 93, 130, 173, 42, 252, 184, 70, 248, 68, 1, 128, 160, 167, 171, 204, 110, 30, 52, 74, 189, 215, 97, 245, 227, 176, 141, 250, 205, 8, 182, 138, 101, 51, 150, 155, 174, 234, 246, 30, 128, 253, 230, 36, 228, 160, 123, 3, 223, 103, 97, 183, 213, 144, 49, 213, 133, 172, 63, 37, 47, 135, 95, 246, 27, 34, 202, 105, 209, 207, 211, 141, 218, 217, 23, 141, 180, 134},
},
},
StorageNodes: [][]snapt.Node{
{},
{},
{
// Branch root node.
{
NodeType: 0,
Path: []byte{},
Value: []byte{248, 81, 128, 128, 160, 79, 197, 241, 58, 178, 249, 186, 12, 45, 168, 139, 1, 81, 171, 14, 124, 244, 216, 93, 8, 204, 164, 92, 205, 146, 60, 106, 183, 99, 35, 235, 40, 128, 128, 128, 128, 128, 128, 128, 128, 160, 244, 152, 74, 17, 246, 26, 41, 33, 69, 97, 65, 223, 136, 222, 110, 26, 113, 13, 40, 104, 27, 145, 175, 121, 76, 90, 114, 30, 71, 131, 156, 215, 128, 128, 128, 128, 128},
},
// Storage node for contract Test1 state variable count.
{
NodeType: 2,
Path: []byte{2},
Key: common.HexToHash("0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563"),
Value: []byte{226, 160, 57, 13, 236, 217, 84, 139, 98, 168, 214, 3, 69, 169, 136, 56, 111, 200, 75, 166, 188, 149, 72, 64, 8, 246, 54, 47, 147, 22, 14, 243, 229, 99, 1},
},
// Storage node for contract Test1 state variable initialCount.
{
NodeType: 2,
Path: []byte{11},
Key: common.HexToHash("0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"),
Value: []byte{226, 160, 49, 14, 45, 82, 118, 18, 7, 59, 38, 238, 205, 253, 113, 126, 106, 50, 12, 244, 75, 74, 250, 194, 176, 115, 45, 159, 203, 226, 183, 250, 12, 246, 1},
},
},
},
},
)
type StorageNodeWithState struct { type StorageNodeWithState struct {
snapt.Node snapt.Node
StatePath []byte StatePath []byte

View File

@ -38,14 +38,6 @@ var (
nodeInfo = test.DefaultNodeInfo nodeInfo = test.DefaultNodeInfo
snapshotHeight = 6 snapshotHeight = 6
allTables = []*snapt.Table{
&snapt.TableIPLDBlock,
&snapt.TableNodeInfo,
&snapt.TableHeader,
&snapt.TableStateNode,
&snapt.TableStorageNode,
}
pgQueryStateCids = `SELECT cast(state_cids.block_number AS TEXT), state_cids.cid, state_cids.state_leaf_key, state_cids.node_type, state_cids.state_path, state_cids.header_id, state_cids.mh_key pgQueryStateCids = `SELECT cast(state_cids.block_number AS TEXT), state_cids.cid, state_cids.state_leaf_key, state_cids.node_type, state_cids.state_path, state_cids.header_id, state_cids.mh_key
FROM eth.state_cids FROM eth.state_cids
WHERE eth.state_cids.block_number = $1 WHERE eth.state_cids.block_number = $1
@ -92,7 +84,7 @@ func TestCreateInPlaceSnapshot(t *testing.T) {
compareStorageNodes(t, db, fixt.ExpectedStorageNodes) compareStorageNodes(t, db, fixt.ExpectedStorageNodes)
}) })
t.Run("Snapshot for blocks with contract deployment and transaction", func(t *testing.T) { t.Run("Snapshot for blocks with contract destruction", func(t *testing.T) {
t.Skip("Fix in-place snapshot function for removed type nodes") t.Skip("Fix in-place snapshot function for removed type nodes")
sql.TearDownDB(t, db) sql.TearDownDB(t, db)
_ = writeData(t, db, fixt.InPlaceSnapshotBlocks[:5]) _ = writeData(t, db, fixt.InPlaceSnapshotBlocks[:5])
@ -123,6 +115,22 @@ func TestCreateInPlaceSnapshot(t *testing.T) {
// Check inplace snapshot was created for storage_cids // Check inplace snapshot was created for storage_cids
compareStorageNodes(t, db, fixt.ExpectedStorageNodes) compareStorageNodes(t, db, fixt.ExpectedStorageNodes)
}) })
t.Run("Snapshot for chain with non indexed missing blocks", func(t *testing.T) {
t.Skip("Fix in-place snapshot function for chain with non-indexed missing blocks")
sql.TearDownDB(t, db)
_ = writeData(t, db, fixt.ChainWithMissingBlock)
params := InPlaceSnapshotParams{StartHeight: uint64(0), EndHeight: uint64(snapshotHeight)}
err = CreateInPlaceSnapshot(config, params)
test.NoError(t, err)
// Check inplace snapshot was created for state_cids
compareStateNodes(t, db, fixt.ExpectedStateNodes)
// Check inplace snapshot was created for storage_cids
compareStorageNodes(t, db, fixt.ExpectedStorageNodes)
})
} }
func writeData(t *testing.T, db *postgres.DB, blocks []fixt.Block) snapt.Publisher { func writeData(t *testing.T, db *postgres.DB, blocks []fixt.Block) snapt.Publisher {