update unit tests
This commit is contained in:
parent
7bc4c7520c
commit
1e64f486d8
@ -33,7 +33,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
|
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/test_helpers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -71,7 +70,7 @@ func setupLegacy(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, tx.(*file.BatchTx).BlockNumber, legacyData.BlockNumber.Uint64())
|
require.Equal(t, legacyData.BlockNumber.String(), tx.(*file.BatchTx).BlockNumber)
|
||||||
|
|
||||||
connStr := postgres.DefaultConfig.DbConnectionString()
|
connStr := postgres.DefaultConfig.DbConnectionString()
|
||||||
|
|
||||||
@ -123,10 +122,10 @@ func TestFileIndexerLegacy(t *testing.T) {
|
|||||||
err = sqlxdb.QueryRowx(pgStr, legacyData.BlockNumber.Uint64()).StructScan(header)
|
err = sqlxdb.QueryRowx(pgStr, legacyData.BlockNumber.Uint64()).StructScan(header)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String())
|
require.Equal(t, legacyHeaderCID.String(), header.CID)
|
||||||
test_helpers.ExpectEqual(t, header.TD, legacyData.MockBlock.Difficulty().String())
|
require.Equal(t, legacyData.MockBlock.Difficulty().String(), header.TD)
|
||||||
test_helpers.ExpectEqual(t, header.Reward, "5000000000000011250")
|
require.Equal(t, "5000000000000011250", header.Reward)
|
||||||
test_helpers.ExpectEqual(t, header.Coinbase, legacyData.MockBlock.Coinbase().String())
|
require.Equal(t, legacyData.MockBlock.Coinbase().String(), header.Coinbase)
|
||||||
require.Nil(t, legacyData.MockHeader.BaseFee)
|
require.Nil(t, legacyData.MockHeader.BaseFee)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ func setup(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, tx.(*file.BatchTx).BlockNumber, mocks.BlockNumber.Uint64())
|
require.Equal(t, mocks.BlockNumber.String(), tx.(*file.BatchTx).BlockNumber)
|
||||||
|
|
||||||
connStr := postgres.DefaultConfig.DbConnectionString()
|
connStr := postgres.DefaultConfig.DbConnectionString()
|
||||||
|
|
||||||
@ -223,10 +223,10 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, header.CID, headerCID.String())
|
require.Equal(t, headerCID.String(), header.CID)
|
||||||
test_helpers.ExpectEqual(t, header.TD, mocks.MockBlock.Difficulty().String())
|
require.Equal(t, mocks.MockBlock.Difficulty().String(), header.TD)
|
||||||
test_helpers.ExpectEqual(t, header.Reward, "2000000000000021250")
|
require.Equal(t, "2000000000000021250", header.Reward)
|
||||||
test_helpers.ExpectEqual(t, header.Coinbase, mocks.MockHeader.Coinbase.String())
|
require.Equal(t, mocks.MockHeader.Coinbase.String(), header.Coinbase)
|
||||||
dc, err := cid.Decode(header.CID)
|
dc, err := cid.Decode(header.CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -238,7 +238,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, mocks.MockHeaderRlp)
|
require.Equal(t, mocks.MockHeaderRlp, data)
|
||||||
})
|
})
|
||||||
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
|
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
|
||||||
setup(t)
|
setup(t)
|
||||||
@ -253,7 +253,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(trxs), 5)
|
require.Equal(t, 5, len(trxs))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx1CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx1CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx2CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx2CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx3CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx3CID.String()))
|
||||||
@ -280,7 +280,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
txTypeAndValueStr := `SELECT tx_type, value FROM eth.transaction_cids WHERE cid = $1`
|
txTypeAndValueStr := `SELECT tx_type, value FROM eth.transaction_cids WHERE cid = $1`
|
||||||
switch c {
|
switch c {
|
||||||
case trx1CID.String():
|
case trx1CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx1)
|
require.Equal(t, tx1, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -293,7 +293,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[0].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[0].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx2CID.String():
|
case trx2CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx2)
|
require.Equal(t, tx2, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -306,7 +306,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[1].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[1].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx3CID.String():
|
case trx3CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx3)
|
require.Equal(t, tx3, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -319,7 +319,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[2].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[2].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx4CID.String():
|
case trx4CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx4)
|
require.Equal(t, tx4, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -332,7 +332,9 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[3].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[3].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
accessListElementModels := make([]models.AccessListElementModel, 0)
|
accessListElementModels := make([]models.AccessListElementModel, 0)
|
||||||
pgStr = `SELECT access_list_elements.* FROM eth.access_list_elements INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.tx_hash) WHERE cid = $1 ORDER BY access_list_elements.index ASC`
|
pgStr = "SELECT cast(access_list_elements.block_number AS TEXT), access_list_elements.index, access_list_elements.tx_id, " +
|
||||||
|
"access_list_elements.address, access_list_elements.storage_keys FROM eth.access_list_elements " +
|
||||||
|
"INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.tx_hash) WHERE cid = $1 ORDER BY access_list_elements.index ASC"
|
||||||
err = sqlxdb.Select(&accessListElementModels, pgStr, c)
|
err = sqlxdb.Select(&accessListElementModels, pgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -341,18 +343,20 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected two access list entries, got %d", len(accessListElementModels))
|
t.Fatalf("expected two access list entries, got %d", len(accessListElementModels))
|
||||||
}
|
}
|
||||||
model1 := models.AccessListElementModel{
|
model1 := models.AccessListElementModel{
|
||||||
Index: accessListElementModels[0].Index,
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
Address: accessListElementModels[0].Address,
|
Index: accessListElementModels[0].Index,
|
||||||
|
Address: accessListElementModels[0].Address,
|
||||||
}
|
}
|
||||||
model2 := models.AccessListElementModel{
|
model2 := models.AccessListElementModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
Index: accessListElementModels[1].Index,
|
Index: accessListElementModels[1].Index,
|
||||||
Address: accessListElementModels[1].Address,
|
Address: accessListElementModels[1].Address,
|
||||||
StorageKeys: accessListElementModels[1].StorageKeys,
|
StorageKeys: accessListElementModels[1].StorageKeys,
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, model1, mocks.AccessListEntry1Model)
|
require.Equal(t, mocks.AccessListEntry1Model, model1)
|
||||||
test_helpers.ExpectEqual(t, model2, mocks.AccessListEntry2Model)
|
require.Equal(t, mocks.AccessListEntry2Model, model2)
|
||||||
case trx5CID.String():
|
case trx5CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx5)
|
require.Equal(t, tx5, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
err = sqlxdb.QueryRowx(txTypeAndValueStr, c).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -402,7 +406,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
|
|
||||||
// expecting MockLog1 and MockLog2 for mockReceipt4
|
// expecting MockLog1 and MockLog2 for mockReceipt4
|
||||||
expectedLogs := mocks.MockReceipts[i].Logs
|
expectedLogs := mocks.MockReceipts[i].Logs
|
||||||
test_helpers.ExpectEqual(t, len(results), len(expectedLogs))
|
require.Equal(t, len(expectedLogs), len(results))
|
||||||
|
|
||||||
var nodeElements []interface{}
|
var nodeElements []interface{}
|
||||||
for idx, r := range results {
|
for idx, r := range results {
|
||||||
@ -413,12 +417,12 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// 2nd element of the leaf node contains the encoded log data.
|
// 2nd element of the leaf node contains the encoded log data.
|
||||||
test_helpers.ExpectEqual(t, logRaw, nodeElements[1].([]byte))
|
require.Equal(t, nodeElements[1].([]byte), logRaw)
|
||||||
} else {
|
} else {
|
||||||
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// raw log was IPLDized
|
// raw log was IPLDized
|
||||||
test_helpers.ExpectEqual(t, logRaw, r.Data)
|
require.Equal(t, r.Data, logRaw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,7 +443,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(rcts), 5)
|
require.Equal(t, 5, len(rcts))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct1CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct1CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct2CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct2CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct3CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct3CID.String()))
|
||||||
@ -465,7 +469,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
expectedRct, err := mocks.MockReceipts[idx].MarshalBinary()
|
expectedRct, err := mocks.MockReceipts[idx].MarshalBinary()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, expectedRct, nodeElements[1].([]byte))
|
require.Equal(t, expectedRct, nodeElements[1].([]byte))
|
||||||
|
|
||||||
dc, err := cid.Decode(c)
|
dc, err := cid.Decode(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -481,46 +485,46 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
|
postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
|
||||||
switch c {
|
switch c {
|
||||||
case rct1CID.String():
|
case rct1CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf1)
|
require.Equal(t, rctLeaf1, data)
|
||||||
var postStatus uint64
|
var postStatus uint64
|
||||||
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE leaf_cid = $1`
|
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE leaf_cid = $1`
|
||||||
err = sqlxdb.Get(&postStatus, pgStr, c)
|
err = sqlxdb.Get(&postStatus, pgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postStatus, mocks.ExpectedPostStatus)
|
require.Equal(t, mocks.ExpectedPostStatus, postStatus)
|
||||||
case rct2CID.String():
|
case rct2CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf2)
|
require.Equal(t, rctLeaf2, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = sqlxdb.Get(&postState, postStatePgStr, c)
|
err = sqlxdb.Get(&postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState1)
|
require.Equal(t, mocks.ExpectedPostState1, postState)
|
||||||
case rct3CID.String():
|
case rct3CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf3)
|
require.Equal(t, rctLeaf3, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = sqlxdb.Get(&postState, postStatePgStr, c)
|
err = sqlxdb.Get(&postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState2)
|
require.Equal(t, mocks.ExpectedPostState2, postState)
|
||||||
case rct4CID.String():
|
case rct4CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf4)
|
require.Equal(t, rctLeaf4, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = sqlxdb.Get(&postState, postStatePgStr, c)
|
err = sqlxdb.Get(&postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
|
require.Equal(t, mocks.ExpectedPostState3, postState)
|
||||||
case rct5CID.String():
|
case rct5CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf5)
|
require.Equal(t, rctLeaf5, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = sqlxdb.Get(&postState, postStatePgStr, c)
|
err = sqlxdb.Get(&postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
|
require.Equal(t, mocks.ExpectedPostState3, postState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -539,7 +543,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(stateNodes), 2)
|
require.Equal(t, 2, len(stateNodes))
|
||||||
for _, stateNode := range stateNodes {
|
for _, stateNode := range stateNodes {
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(stateNode.CID)
|
dc, err := cid.Decode(stateNode.CID)
|
||||||
@ -552,39 +556,41 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
pgStr = `SELECT * from eth.state_accounts WHERE header_id = $1 AND state_path = $2`
|
pgStr = `SELECT cast(block_number AS TEXT), header_id, state_path, cast(balance AS TEXT), nonce, code_hash, storage_root from eth.state_accounts WHERE header_id = $1 AND state_path = $2`
|
||||||
var account models.StateAccountModel
|
var account models.StateAccountModel
|
||||||
err = sqlxdb.Get(&account, pgStr, stateNode.HeaderID, stateNode.Path)
|
err = sqlxdb.Get(&account, pgStr, stateNode.HeaderID, stateNode.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if stateNode.CID == state1CID.String() {
|
if stateNode.CID == state1CID.String() {
|
||||||
test_helpers.ExpectEqual(t, stateNode.NodeType, 2)
|
require.Equal(t, 2, stateNode.NodeType)
|
||||||
test_helpers.ExpectEqual(t, stateNode.StateKey, common.BytesToHash(mocks.ContractLeafKey).Hex())
|
require.Equal(t, common.BytesToHash(mocks.ContractLeafKey).Hex(), stateNode.StateKey)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x06'})
|
require.Equal(t, []byte{'\x06'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, mocks.ContractLeafNode)
|
require.Equal(t, mocks.ContractLeafNode, data)
|
||||||
test_helpers.ExpectEqual(t, account, models.StateAccountModel{
|
require.Equal(t, models.StateAccountModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
HeaderID: account.HeaderID,
|
HeaderID: account.HeaderID,
|
||||||
StatePath: stateNode.Path,
|
StatePath: stateNode.Path,
|
||||||
Balance: "0",
|
Balance: "0",
|
||||||
CodeHash: mocks.ContractCodeHash.Bytes(),
|
CodeHash: mocks.ContractCodeHash.Bytes(),
|
||||||
StorageRoot: mocks.ContractRoot,
|
StorageRoot: mocks.ContractRoot,
|
||||||
Nonce: 1,
|
Nonce: 1,
|
||||||
})
|
}, account)
|
||||||
}
|
}
|
||||||
if stateNode.CID == state2CID.String() {
|
if stateNode.CID == state2CID.String() {
|
||||||
test_helpers.ExpectEqual(t, stateNode.NodeType, 2)
|
require.Equal(t, 2, stateNode.NodeType)
|
||||||
test_helpers.ExpectEqual(t, stateNode.StateKey, common.BytesToHash(mocks.AccountLeafKey).Hex())
|
require.Equal(t, common.BytesToHash(mocks.AccountLeafKey).Hex(), stateNode.StateKey)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x0c'})
|
require.Equal(t, []byte{'\x0c'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, mocks.AccountLeafNode)
|
require.Equal(t, mocks.AccountLeafNode, data)
|
||||||
test_helpers.ExpectEqual(t, account, models.StateAccountModel{
|
require.Equal(t, models.StateAccountModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
HeaderID: account.HeaderID,
|
HeaderID: account.HeaderID,
|
||||||
StatePath: stateNode.Path,
|
StatePath: stateNode.Path,
|
||||||
Balance: "1000",
|
Balance: "1000",
|
||||||
CodeHash: mocks.AccountCodeHash.Bytes(),
|
CodeHash: mocks.AccountCodeHash.Bytes(),
|
||||||
StorageRoot: mocks.AccountRoot,
|
StorageRoot: mocks.AccountRoot,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
})
|
}, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,7 +603,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(stateNodes), 1)
|
require.Equal(t, 1, len(stateNodes))
|
||||||
stateNode := stateNodes[0]
|
stateNode := stateNodes[0]
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(stateNode.CID)
|
dc, err := cid.Decode(stateNode.CID)
|
||||||
@ -606,14 +612,14 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
test_helpers.ExpectEqual(t, prefixedKey, shared.RemovedNodeMhKey)
|
require.Equal(t, shared.RemovedNodeMhKey, prefixedKey)
|
||||||
err = sqlxdb.Get(&data, ipfsPgGet, prefixedKey)
|
err = sqlxdb.Get(&data, ipfsPgGet, prefixedKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, stateNode.CID, shared.RemovedNodeStateCID)
|
require.Equal(t, shared.RemovedNodeStateCID, stateNode.CID)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x02'})
|
require.Equal(t, []byte{'\x02'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, []byte{})
|
require.Equal(t, []byte{}, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Publish and index storage IPLDs in a single tx", func(t *testing.T) {
|
t.Run("Publish and index storage IPLDs in a single tx", func(t *testing.T) {
|
||||||
@ -623,7 +629,7 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
|
|
||||||
// check that storage nodes were properly indexed
|
// check that storage nodes were properly indexed
|
||||||
storageNodes := make([]models.StorageNodeWithStateKeyModel, 0)
|
storageNodes := make([]models.StorageNodeWithStateKeyModel, 0)
|
||||||
pgStr := `SELECT storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
pgStr := `SELECT cast(storage_cids.block_number AS TEXT), storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
||||||
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
||||||
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
||||||
AND state_cids.header_id = header_cids.block_hash
|
AND state_cids.header_id = header_cids.block_hash
|
||||||
@ -633,14 +639,15 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(storageNodes), 1)
|
require.Equal(t, 1, len(storageNodes))
|
||||||
test_helpers.ExpectEqual(t, storageNodes[0], models.StorageNodeWithStateKeyModel{
|
require.Equal(t, models.StorageNodeWithStateKeyModel{
|
||||||
CID: storageCID.String(),
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
NodeType: 2,
|
CID: storageCID.String(),
|
||||||
StorageKey: common.BytesToHash(mocks.StorageLeafKey).Hex(),
|
NodeType: 2,
|
||||||
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
StorageKey: common.BytesToHash(mocks.StorageLeafKey).Hex(),
|
||||||
Path: []byte{},
|
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
||||||
})
|
Path: []byte{},
|
||||||
|
}, storageNodes[0])
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(storageNodes[0].CID)
|
dc, err := cid.Decode(storageNodes[0].CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -652,11 +659,11 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, mocks.StorageLeafNode)
|
require.Equal(t, mocks.StorageLeafNode, data)
|
||||||
|
|
||||||
// check that Removed storage nodes were properly indexed
|
// check that Removed storage nodes were properly indexed
|
||||||
storageNodes = make([]models.StorageNodeWithStateKeyModel, 0)
|
storageNodes = make([]models.StorageNodeWithStateKeyModel, 0)
|
||||||
pgStr = `SELECT storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
pgStr = `SELECT cast(storage_cids.block_number AS TEXT), storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
||||||
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
||||||
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
||||||
AND state_cids.header_id = header_cids.block_hash
|
AND state_cids.header_id = header_cids.block_hash
|
||||||
@ -666,25 +673,26 @@ func TestFileIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(storageNodes), 1)
|
require.Equal(t, 1, len(storageNodes))
|
||||||
test_helpers.ExpectEqual(t, storageNodes[0], models.StorageNodeWithStateKeyModel{
|
require.Equal(t, models.StorageNodeWithStateKeyModel{
|
||||||
CID: shared.RemovedNodeStorageCID,
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
NodeType: 3,
|
CID: shared.RemovedNodeStorageCID,
|
||||||
StorageKey: common.BytesToHash(mocks.RemovedLeafKey).Hex(),
|
NodeType: 3,
|
||||||
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
StorageKey: common.BytesToHash(mocks.RemovedLeafKey).Hex(),
|
||||||
Path: []byte{'\x03'},
|
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
||||||
})
|
Path: []byte{'\x03'},
|
||||||
|
}, storageNodes[0])
|
||||||
dc, err = cid.Decode(storageNodes[0].CID)
|
dc, err = cid.Decode(storageNodes[0].CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
mhKey = dshelp.MultihashToDsKey(dc.Hash())
|
mhKey = dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey = blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey = blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
test_helpers.ExpectEqual(t, prefixedKey, shared.RemovedNodeMhKey)
|
require.Equal(t, shared.RemovedNodeMhKey, prefixedKey)
|
||||||
err = sqlxdb.Get(&data, ipfsPgGet, prefixedKey)
|
err = sqlxdb.Get(&data, ipfsPgGet, prefixedKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, []byte{})
|
require.Equal(t, []byte{}, data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ var (
|
|||||||
err error
|
err error
|
||||||
ind interfaces.StateDiffIndexer
|
ind interfaces.StateDiffIndexer
|
||||||
ipfsPgGet = `SELECT data FROM public.blocks
|
ipfsPgGet = `SELECT data FROM public.blocks
|
||||||
WHERE key = $1`
|
WHERE key = $1 AND block_number = $2`
|
||||||
tx1, tx2, tx3, tx4, tx5, rct1, rct2, rct3, rct4, rct5 []byte
|
tx1, tx2, tx3, tx4, tx5, rct1, rct2, rct3, rct4, rct5 []byte
|
||||||
mockBlock *types.Block
|
mockBlock *types.Block
|
||||||
headerCID, trx1CID, trx2CID, trx3CID, trx4CID, trx5CID cid.Cid
|
headerCID, trx1CID, trx2CID, trx3CID, trx4CID, trx5CID cid.Cid
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/test_helpers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupLegacyPGX(t *testing.T) {
|
func setupLegacyPGX(t *testing.T) {
|
||||||
@ -56,7 +55,7 @@ func setupLegacyPGX(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, legacyData.BlockNumber.Uint64())
|
require.Equal(t, legacyData.BlockNumber.String(), tx.(*sql.BatchTx).BlockNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLegacyPGXIndexer(t *testing.T) {
|
func TestLegacyPGXIndexer(t *testing.T) {
|
||||||
@ -81,10 +80,10 @@ func TestLegacyPGXIndexer(t *testing.T) {
|
|||||||
&header.CID, &header.TD, &header.Reward, &header.BlockHash, &header.Coinbase)
|
&header.CID, &header.TD, &header.Reward, &header.BlockHash, &header.Coinbase)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String())
|
require.Equal(t, legacyHeaderCID.String(), header.CID)
|
||||||
test_helpers.ExpectEqual(t, header.TD, legacyData.MockBlock.Difficulty().String())
|
require.Equal(t, legacyData.MockBlock.Difficulty().String(), header.TD)
|
||||||
test_helpers.ExpectEqual(t, header.Reward, "5000000000000011250")
|
require.Equal(t, "5000000000000011250", header.Reward)
|
||||||
test_helpers.ExpectEqual(t, header.Coinbase, legacyData.MockHeader.Coinbase.String())
|
require.Equal(t, legacyData.MockHeader.Coinbase.String(), header.Coinbase)
|
||||||
require.Nil(t, legacyData.MockHeader.BaseFee)
|
require.Nil(t, legacyData.MockHeader.BaseFee)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/lib/pq"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||||
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
||||||
@ -62,7 +64,7 @@ func setupPGX(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, mocks.BlockNumber.Uint64())
|
require.Equal(t, mocks.BlockNumber.String(), tx.(*sql.BatchTx).BlockNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPGXIndexer(t *testing.T) {
|
func TestPGXIndexer(t *testing.T) {
|
||||||
@ -91,10 +93,10 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, header.CID, headerCID.String())
|
require.Equal(t, headerCID.String(), header.CID)
|
||||||
test_helpers.ExpectEqual(t, header.TD, mocks.MockBlock.Difficulty().String())
|
require.Equal(t, mocks.MockBlock.Difficulty().String(), header.TD)
|
||||||
test_helpers.ExpectEqual(t, header.Reward, "2000000000000021250")
|
require.Equal(t, "2000000000000021250", header.Reward)
|
||||||
test_helpers.ExpectEqual(t, header.Coinbase, mocks.MockHeader.Coinbase.String())
|
require.Equal(t, mocks.MockHeader.Coinbase.String(), header.Coinbase)
|
||||||
dc, err := cid.Decode(header.CID)
|
dc, err := cid.Decode(header.CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -102,11 +104,11 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
var data []byte
|
var data []byte
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, mocks.MockHeaderRlp)
|
require.Equal(t, mocks.MockHeaderRlp, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
|
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
|
||||||
@ -121,7 +123,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(trxs), 5)
|
require.Equal(t, 5, len(trxs))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx1CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx1CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx2CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx2CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx3CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx3CID.String()))
|
||||||
@ -141,14 +143,14 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
var data []byte
|
var data []byte
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
txTypeAndValueStr := `SELECT tx_type, CAST(value as TEXT) FROM eth.transaction_cids WHERE cid = $1`
|
txTypeAndValueStr := `SELECT tx_type, CAST(value as TEXT) FROM eth.transaction_cids WHERE cid = $1`
|
||||||
switch c {
|
switch c {
|
||||||
case trx1CID.String():
|
case trx1CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx1)
|
require.Equal(t, tx1, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -161,7 +163,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[0].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[0].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx2CID.String():
|
case trx2CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx2)
|
require.Equal(t, tx2, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -174,7 +176,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[1].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[1].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx3CID.String():
|
case trx3CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx3)
|
require.Equal(t, tx3, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -187,7 +189,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[2].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[2].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx4CID.String():
|
case trx4CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx4)
|
require.Equal(t, tx4, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -199,8 +201,18 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
if txRes.Value != transactions[3].Value().String() {
|
if txRes.Value != transactions[3].Value().String() {
|
||||||
t.Fatalf("expected tx value %s got %s", transactions[3].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[3].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
|
// AccessListElementModel is the db model for eth.access_list_entry
|
||||||
|
type AccessListElementModel struct {
|
||||||
|
BlockNumber string `db:"block_number"`
|
||||||
|
Index int64 `db:"index"`
|
||||||
|
TxID string `db:"tx_id"`
|
||||||
|
Address string `db:"address"`
|
||||||
|
StorageKeys pq.StringArray `db:"storage_keys"`
|
||||||
|
}
|
||||||
accessListElementModels := make([]models.AccessListElementModel, 0)
|
accessListElementModels := make([]models.AccessListElementModel, 0)
|
||||||
pgStr = `SELECT access_list_elements.* FROM eth.access_list_elements INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.tx_hash) WHERE cid = $1 ORDER BY access_list_elements.index ASC`
|
pgStr = "SELECT cast(access_list_elements.block_number AS TEXT), access_list_elements.index, access_list_elements.tx_id, " +
|
||||||
|
"access_list_elements.address, access_list_elements.storage_keys FROM eth.access_list_elements " +
|
||||||
|
"INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.tx_hash) WHERE cid = $1 ORDER BY access_list_elements.index ASC"
|
||||||
err = db.Select(context.Background(), &accessListElementModels, pgStr, c)
|
err = db.Select(context.Background(), &accessListElementModels, pgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -209,18 +221,20 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected two access list entries, got %d", len(accessListElementModels))
|
t.Fatalf("expected two access list entries, got %d", len(accessListElementModels))
|
||||||
}
|
}
|
||||||
model1 := models.AccessListElementModel{
|
model1 := models.AccessListElementModel{
|
||||||
Index: accessListElementModels[0].Index,
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
Address: accessListElementModels[0].Address,
|
Index: accessListElementModels[0].Index,
|
||||||
|
Address: accessListElementModels[0].Address,
|
||||||
}
|
}
|
||||||
model2 := models.AccessListElementModel{
|
model2 := models.AccessListElementModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
Index: accessListElementModels[1].Index,
|
Index: accessListElementModels[1].Index,
|
||||||
Address: accessListElementModels[1].Address,
|
Address: accessListElementModels[1].Address,
|
||||||
StorageKeys: accessListElementModels[1].StorageKeys,
|
StorageKeys: accessListElementModels[1].StorageKeys,
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, model1, mocks.AccessListEntry1Model)
|
require.Equal(t, mocks.AccessListEntry1Model, model1)
|
||||||
test_helpers.ExpectEqual(t, model2, mocks.AccessListEntry2Model)
|
require.Equal(t, mocks.AccessListEntry2Model, model2)
|
||||||
case trx5CID.String():
|
case trx5CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx5)
|
require.Equal(t, tx5, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).Scan(&txRes.TxType, &txRes.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -272,7 +286,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expectedLogs := mocks.MockReceipts[i].Logs
|
expectedLogs := mocks.MockReceipts[i].Logs
|
||||||
test_helpers.ExpectEqual(t, len(results), len(expectedLogs))
|
require.Equal(t, len(expectedLogs), len(results))
|
||||||
|
|
||||||
var nodeElements []interface{}
|
var nodeElements []interface{}
|
||||||
for idx, r := range results {
|
for idx, r := range results {
|
||||||
@ -283,12 +297,12 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// 2nd element of the leaf node contains the encoded log data.
|
// 2nd element of the leaf node contains the encoded log data.
|
||||||
test_helpers.ExpectEqual(t, logRaw, nodeElements[1].([]byte))
|
require.Equal(t, nodeElements[1].([]byte), logRaw)
|
||||||
} else {
|
} else {
|
||||||
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// raw log was IPLDized
|
// raw log was IPLDized
|
||||||
test_helpers.ExpectEqual(t, logRaw, r.Data)
|
require.Equal(t, r.Data, logRaw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +323,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(rcts), 5)
|
require.Equal(t, 5, len(rcts))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct1CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct1CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct2CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct2CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct3CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct3CID.String()))
|
||||||
@ -335,7 +349,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
expectedRct, err := mocks.MockReceipts[idx].MarshalBinary()
|
expectedRct, err := mocks.MockReceipts[idx].MarshalBinary()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, expectedRct, nodeElements[1].([]byte))
|
require.Equal(t, nodeElements[1].([]byte), expectedRct)
|
||||||
|
|
||||||
dc, err := cid.Decode(c)
|
dc, err := cid.Decode(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -344,7 +358,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
var data []byte
|
var data []byte
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -352,46 +366,46 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
|
postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
|
||||||
switch c {
|
switch c {
|
||||||
case rct1CID.String():
|
case rct1CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf1)
|
require.Equal(t, rctLeaf1, data)
|
||||||
var postStatus uint64
|
var postStatus uint64
|
||||||
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE leaf_cid = $1`
|
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE leaf_cid = $1`
|
||||||
err = db.Get(context.Background(), &postStatus, pgStr, c)
|
err = db.Get(context.Background(), &postStatus, pgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postStatus, mocks.ExpectedPostStatus)
|
require.Equal(t, mocks.ExpectedPostStatus, postStatus)
|
||||||
case rct2CID.String():
|
case rct2CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf2)
|
require.Equal(t, rctLeaf2, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState1)
|
require.Equal(t, mocks.ExpectedPostState1, postState)
|
||||||
case rct3CID.String():
|
case rct3CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf3)
|
require.Equal(t, rctLeaf3, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState2)
|
require.Equal(t, mocks.ExpectedPostState2, postState)
|
||||||
case rct4CID.String():
|
case rct4CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf4)
|
require.Equal(t, rctLeaf4, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
|
require.Equal(t, mocks.ExpectedPostState3, postState)
|
||||||
case rct5CID.String():
|
case rct5CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf5)
|
require.Equal(t, rctLeaf5, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
|
require.Equal(t, mocks.ExpectedPostState3, postState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -409,7 +423,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(stateNodes), 2)
|
require.Equal(t, 2, len(stateNodes))
|
||||||
for _, stateNode := range stateNodes {
|
for _, stateNode := range stateNodes {
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(stateNode.CID)
|
dc, err := cid.Decode(stateNode.CID)
|
||||||
@ -418,43 +432,45 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
pgStr = `SELECT header_id, state_path, cast(balance AS TEXT), nonce, code_hash, storage_root from eth.state_accounts WHERE header_id = $1 AND state_path = $2`
|
pgStr = `SELECT cast(block_number AS TEXT), header_id, state_path, cast(balance AS TEXT), nonce, code_hash, storage_root from eth.state_accounts WHERE header_id = $1 AND state_path = $2`
|
||||||
var account models.StateAccountModel
|
var account models.StateAccountModel
|
||||||
err = db.Get(context.Background(), &account, pgStr, stateNode.HeaderID, stateNode.Path)
|
err = db.Get(context.Background(), &account, pgStr, stateNode.HeaderID, stateNode.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if stateNode.CID == state1CID.String() {
|
if stateNode.CID == state1CID.String() {
|
||||||
test_helpers.ExpectEqual(t, stateNode.NodeType, 2)
|
require.Equal(t, 2, stateNode.NodeType)
|
||||||
test_helpers.ExpectEqual(t, stateNode.StateKey, common.BytesToHash(mocks.ContractLeafKey).Hex())
|
require.Equal(t, common.BytesToHash(mocks.ContractLeafKey).Hex(), stateNode.StateKey)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x06'})
|
require.Equal(t, []byte{'\x06'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, mocks.ContractLeafNode)
|
require.Equal(t, mocks.ContractLeafNode, data)
|
||||||
test_helpers.ExpectEqual(t, account, models.StateAccountModel{
|
require.Equal(t, models.StateAccountModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
HeaderID: account.HeaderID,
|
HeaderID: account.HeaderID,
|
||||||
StatePath: stateNode.Path,
|
StatePath: stateNode.Path,
|
||||||
Balance: "0",
|
Balance: "0",
|
||||||
CodeHash: mocks.ContractCodeHash.Bytes(),
|
CodeHash: mocks.ContractCodeHash.Bytes(),
|
||||||
StorageRoot: mocks.ContractRoot,
|
StorageRoot: mocks.ContractRoot,
|
||||||
Nonce: 1,
|
Nonce: 1,
|
||||||
})
|
}, account)
|
||||||
}
|
}
|
||||||
if stateNode.CID == state2CID.String() {
|
if stateNode.CID == state2CID.String() {
|
||||||
test_helpers.ExpectEqual(t, stateNode.NodeType, 2)
|
require.Equal(t, 2, stateNode.NodeType)
|
||||||
test_helpers.ExpectEqual(t, stateNode.StateKey, common.BytesToHash(mocks.AccountLeafKey).Hex())
|
require.Equal(t, common.BytesToHash(mocks.AccountLeafKey).Hex(), stateNode.StateKey)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x0c'})
|
require.Equal(t, []byte{'\x0c'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, mocks.AccountLeafNode)
|
require.Equal(t, mocks.AccountLeafNode, data)
|
||||||
test_helpers.ExpectEqual(t, account, models.StateAccountModel{
|
require.Equal(t, models.StateAccountModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
HeaderID: account.HeaderID,
|
HeaderID: account.HeaderID,
|
||||||
StatePath: stateNode.Path,
|
StatePath: stateNode.Path,
|
||||||
Balance: "1000",
|
Balance: "1000",
|
||||||
CodeHash: mocks.AccountCodeHash.Bytes(),
|
CodeHash: mocks.AccountCodeHash.Bytes(),
|
||||||
StorageRoot: mocks.AccountRoot,
|
StorageRoot: mocks.AccountRoot,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
})
|
}, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +483,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(stateNodes), 1)
|
require.Equal(t, 1, len(stateNodes))
|
||||||
stateNode := stateNodes[0]
|
stateNode := stateNodes[0]
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(stateNode.CID)
|
dc, err := cid.Decode(stateNode.CID)
|
||||||
@ -476,14 +492,14 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
test_helpers.ExpectEqual(t, prefixedKey, shared.RemovedNodeMhKey)
|
require.Equal(t, shared.RemovedNodeMhKey, prefixedKey)
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, stateNode.CID, shared.RemovedNodeStateCID)
|
require.Equal(t, shared.RemovedNodeStateCID, stateNode.CID)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x02'})
|
require.Equal(t, []byte{'\x02'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, []byte{})
|
require.Equal(t, []byte{}, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Publish and index storage IPLDs in a single tx", func(t *testing.T) {
|
t.Run("Publish and index storage IPLDs in a single tx", func(t *testing.T) {
|
||||||
@ -492,7 +508,7 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
defer checkTxClosure(t, 1, 0, 1)
|
defer checkTxClosure(t, 1, 0, 1)
|
||||||
// check that storage nodes were properly indexed
|
// check that storage nodes were properly indexed
|
||||||
storageNodes := make([]models.StorageNodeWithStateKeyModel, 0)
|
storageNodes := make([]models.StorageNodeWithStateKeyModel, 0)
|
||||||
pgStr := `SELECT storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
pgStr := `SELECT cast(storage_cids.block_number AS TEXT), storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
||||||
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
||||||
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
||||||
AND state_cids.header_id = header_cids.block_hash
|
AND state_cids.header_id = header_cids.block_hash
|
||||||
@ -502,14 +518,15 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(storageNodes), 1)
|
require.Equal(t, 1, len(storageNodes))
|
||||||
test_helpers.ExpectEqual(t, storageNodes[0], models.StorageNodeWithStateKeyModel{
|
require.Equal(t, models.StorageNodeWithStateKeyModel{
|
||||||
CID: storageCID.String(),
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
NodeType: 2,
|
CID: storageCID.String(),
|
||||||
StorageKey: common.BytesToHash(mocks.StorageLeafKey).Hex(),
|
NodeType: 2,
|
||||||
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
StorageKey: common.BytesToHash(mocks.StorageLeafKey).Hex(),
|
||||||
Path: []byte{},
|
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
||||||
})
|
Path: []byte{},
|
||||||
|
}, storageNodes[0])
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(storageNodes[0].CID)
|
dc, err := cid.Decode(storageNodes[0].CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -517,15 +534,15 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, mocks.StorageLeafNode)
|
require.Equal(t, mocks.StorageLeafNode, data)
|
||||||
|
|
||||||
// check that Removed storage nodes were properly indexed
|
// check that Removed storage nodes were properly indexed
|
||||||
storageNodes = make([]models.StorageNodeWithStateKeyModel, 0)
|
storageNodes = make([]models.StorageNodeWithStateKeyModel, 0)
|
||||||
pgStr = `SELECT storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
pgStr = `SELECT cast(storage_cids.block_number AS TEXT), storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
||||||
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
||||||
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
||||||
AND state_cids.header_id = header_cids.block_hash
|
AND state_cids.header_id = header_cids.block_hash
|
||||||
@ -535,25 +552,26 @@ func TestPGXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(storageNodes), 1)
|
require.Equal(t, 1, len(storageNodes))
|
||||||
test_helpers.ExpectEqual(t, storageNodes[0], models.StorageNodeWithStateKeyModel{
|
require.Equal(t, models.StorageNodeWithStateKeyModel{
|
||||||
CID: shared.RemovedNodeStorageCID,
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
NodeType: 3,
|
CID: shared.RemovedNodeStorageCID,
|
||||||
StorageKey: common.BytesToHash(mocks.RemovedLeafKey).Hex(),
|
NodeType: 3,
|
||||||
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
StorageKey: common.BytesToHash(mocks.RemovedLeafKey).Hex(),
|
||||||
Path: []byte{'\x03'},
|
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
||||||
})
|
Path: []byte{'\x03'},
|
||||||
|
}, storageNodes[0])
|
||||||
dc, err = cid.Decode(storageNodes[0].CID)
|
dc, err = cid.Decode(storageNodes[0].CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
mhKey = dshelp.MultihashToDsKey(dc.Hash())
|
mhKey = dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey = blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey = blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
test_helpers.ExpectEqual(t, prefixedKey, shared.RemovedNodeMhKey)
|
require.Equal(t, shared.RemovedNodeMhKey, prefixedKey)
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, []byte{})
|
require.Equal(t, []byte{}, data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,9 @@ func ResolveDriverType(str string) (DriverType, error) {
|
|||||||
var DefaultConfig = Config{
|
var DefaultConfig = Config{
|
||||||
Hostname: "localhost",
|
Hostname: "localhost",
|
||||||
Port: 5432,
|
Port: 5432,
|
||||||
DatabaseName: "vulcanize_testing_v3",
|
DatabaseName: "vulcanize_testing_v4",
|
||||||
Username: "vdbm",
|
Username: "postgres",
|
||||||
Password: "password",
|
Password: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config holds params for a Postgres db
|
// Config holds params for a Postgres db
|
||||||
|
@ -31,7 +31,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
|
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
|
||||||
"github.com/ethereum/go-ethereum/statediff/indexer/test_helpers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -66,7 +65,7 @@ func setupLegacySQLX(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, legacyData.BlockNumber.Uint64())
|
require.Equal(t, legacyData.BlockNumber.String(), tx.(*sql.BatchTx).BlockNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLegacySQLXIndexer(t *testing.T) {
|
func TestLegacySQLXIndexer(t *testing.T) {
|
||||||
@ -89,10 +88,10 @@ func TestLegacySQLXIndexer(t *testing.T) {
|
|||||||
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
|
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String())
|
require.Equal(t, legacyHeaderCID.String(), header.CID)
|
||||||
test_helpers.ExpectEqual(t, header.TD, legacyData.MockBlock.Difficulty().String())
|
require.Equal(t, legacyData.MockBlock.Difficulty().String(), header.TD)
|
||||||
test_helpers.ExpectEqual(t, header.Reward, "5000000000000011250")
|
require.Equal(t, "5000000000000011250", header.Reward)
|
||||||
test_helpers.ExpectEqual(t, header.Coinbase, legacyData.MockHeader.Coinbase.String())
|
require.Equal(t, legacyData.MockHeader.Coinbase.String(), header.Coinbase)
|
||||||
require.Nil(t, legacyData.MockHeader.BaseFee)
|
require.Nil(t, legacyData.MockHeader.BaseFee)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func setupSQLX(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, mocks.BlockNumber.Uint64())
|
require.Equal(t, mocks.BlockNumber.String(), tx.(*sql.BatchTx).BlockNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSQLXIndexer(t *testing.T) {
|
func TestSQLXIndexer(t *testing.T) {
|
||||||
@ -87,10 +87,10 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, header.CID, headerCID.String())
|
require.Equal(t, headerCID.String(), header.CID)
|
||||||
test_helpers.ExpectEqual(t, header.TD, mocks.MockBlock.Difficulty().String())
|
require.Equal(t, mocks.MockBlock.Difficulty().String(), header.TD)
|
||||||
test_helpers.ExpectEqual(t, header.Reward, "2000000000000021250")
|
require.Equal(t, "2000000000000021250", header.Reward)
|
||||||
test_helpers.ExpectEqual(t, header.Coinbase, mocks.MockHeader.Coinbase.String())
|
require.Equal(t, mocks.MockHeader.Coinbase.String(), header.Coinbase)
|
||||||
dc, err := cid.Decode(header.CID)
|
dc, err := cid.Decode(header.CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -98,11 +98,11 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
var data []byte
|
var data []byte
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, mocks.MockHeaderRlp)
|
require.Equal(t, mocks.MockHeaderRlp, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
|
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
|
||||||
@ -117,7 +117,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(trxs), 5)
|
require.Equal(t, 5, len(trxs))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx1CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx1CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx2CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx2CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(trxs, trx3CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(trxs, trx3CID.String()))
|
||||||
@ -137,14 +137,14 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
var data []byte
|
var data []byte
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
txTypeAndValueStr := `SELECT tx_type, value FROM eth.transaction_cids WHERE cid = $1`
|
txTypeAndValueStr := `SELECT tx_type, value FROM eth.transaction_cids WHERE cid = $1`
|
||||||
switch c {
|
switch c {
|
||||||
case trx1CID.String():
|
case trx1CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx1)
|
require.Equal(t, tx1, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -157,7 +157,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[0].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[0].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx2CID.String():
|
case trx2CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx2)
|
require.Equal(t, tx2, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -170,7 +170,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[1].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[1].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx3CID.String():
|
case trx3CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx3)
|
require.Equal(t, tx3, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -183,7 +183,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[2].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[2].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
case trx4CID.String():
|
case trx4CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx4)
|
require.Equal(t, tx4, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -196,7 +196,9 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected tx value %s got %s", transactions[3].Value().String(), txRes.Value)
|
t.Fatalf("expected tx value %s got %s", transactions[3].Value().String(), txRes.Value)
|
||||||
}
|
}
|
||||||
accessListElementModels := make([]models.AccessListElementModel, 0)
|
accessListElementModels := make([]models.AccessListElementModel, 0)
|
||||||
pgStr = `SELECT access_list_elements.* FROM eth.access_list_elements INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.tx_hash) WHERE cid = $1 ORDER BY access_list_elements.index ASC`
|
pgStr = "SELECT cast(access_list_elements.block_number AS TEXT), access_list_elements.index, access_list_elements.tx_id, " +
|
||||||
|
"access_list_elements.address, access_list_elements.storage_keys FROM eth.access_list_elements " +
|
||||||
|
"INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.tx_hash) WHERE cid = $1 ORDER BY access_list_elements.index ASC"
|
||||||
err = db.Select(context.Background(), &accessListElementModels, pgStr, c)
|
err = db.Select(context.Background(), &accessListElementModels, pgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -205,18 +207,20 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
t.Fatalf("expected two access list entries, got %d", len(accessListElementModels))
|
t.Fatalf("expected two access list entries, got %d", len(accessListElementModels))
|
||||||
}
|
}
|
||||||
model1 := models.AccessListElementModel{
|
model1 := models.AccessListElementModel{
|
||||||
Index: accessListElementModels[0].Index,
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
Address: accessListElementModels[0].Address,
|
Index: accessListElementModels[0].Index,
|
||||||
|
Address: accessListElementModels[0].Address,
|
||||||
}
|
}
|
||||||
model2 := models.AccessListElementModel{
|
model2 := models.AccessListElementModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
Index: accessListElementModels[1].Index,
|
Index: accessListElementModels[1].Index,
|
||||||
Address: accessListElementModels[1].Address,
|
Address: accessListElementModels[1].Address,
|
||||||
StorageKeys: accessListElementModels[1].StorageKeys,
|
StorageKeys: accessListElementModels[1].StorageKeys,
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, model1, mocks.AccessListEntry1Model)
|
require.Equal(t, mocks.AccessListEntry1Model, model1)
|
||||||
test_helpers.ExpectEqual(t, model2, mocks.AccessListEntry2Model)
|
require.Equal(t, mocks.AccessListEntry2Model, model2)
|
||||||
case trx5CID.String():
|
case trx5CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, tx5)
|
require.Equal(t, tx5, data)
|
||||||
txRes := new(txResult)
|
txRes := new(txResult)
|
||||||
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
err = db.QueryRow(context.Background(), txTypeAndValueStr, c).(*sqlx.Row).StructScan(txRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -266,7 +270,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expectedLogs := mocks.MockReceipts[i].Logs
|
expectedLogs := mocks.MockReceipts[i].Logs
|
||||||
test_helpers.ExpectEqual(t, len(results), len(expectedLogs))
|
require.Equal(t, len(expectedLogs), len(results))
|
||||||
|
|
||||||
var nodeElements []interface{}
|
var nodeElements []interface{}
|
||||||
for idx, r := range results {
|
for idx, r := range results {
|
||||||
@ -277,12 +281,12 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// 2nd element of the leaf node contains the encoded log data.
|
// 2nd element of the leaf node contains the encoded log data.
|
||||||
test_helpers.ExpectEqual(t, logRaw, nodeElements[1].([]byte))
|
require.Equal(t, nodeElements[1].([]byte), logRaw)
|
||||||
} else {
|
} else {
|
||||||
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
logRaw, err := rlp.EncodeToBytes(expectedLogs[idx])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// raw log was IPLDized
|
// raw log was IPLDized
|
||||||
test_helpers.ExpectEqual(t, logRaw, r.Data)
|
require.Equal(t, r.Data, logRaw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,7 +307,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(rcts), 5)
|
require.Equal(t, 5, len(rcts))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct1CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct1CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct2CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct2CID.String()))
|
||||||
expectTrue(t, test_helpers.ListContainsString(rcts, rct3CID.String()))
|
expectTrue(t, test_helpers.ListContainsString(rcts, rct3CID.String()))
|
||||||
@ -329,7 +333,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
expectedRct, err := mocks.MockReceipts[idx].MarshalBinary()
|
expectedRct, err := mocks.MockReceipts[idx].MarshalBinary()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
test_helpers.ExpectEqual(t, expectedRct, nodeElements[1].([]byte))
|
require.Equal(t, nodeElements[1].([]byte), expectedRct)
|
||||||
|
|
||||||
dc, err := cid.Decode(c)
|
dc, err := cid.Decode(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -338,53 +342,53 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
var data []byte
|
var data []byte
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
|
postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
|
||||||
switch c {
|
switch c {
|
||||||
case rct1CID.String():
|
case rct1CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf1)
|
require.Equal(t, rctLeaf1, data)
|
||||||
var postStatus uint64
|
var postStatus uint64
|
||||||
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE leaf_cid = $1`
|
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE leaf_cid = $1`
|
||||||
err = db.Get(context.Background(), &postStatus, pgStr, c)
|
err = db.Get(context.Background(), &postStatus, pgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postStatus, mocks.ExpectedPostStatus)
|
require.Equal(t, mocks.ExpectedPostStatus, postStatus)
|
||||||
case rct2CID.String():
|
case rct2CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf2)
|
require.Equal(t, rctLeaf2, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState1)
|
require.Equal(t, mocks.ExpectedPostState1, postState)
|
||||||
case rct3CID.String():
|
case rct3CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf3)
|
require.Equal(t, rctLeaf3, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState2)
|
require.Equal(t, mocks.ExpectedPostState2, postState)
|
||||||
case rct4CID.String():
|
case rct4CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf4)
|
require.Equal(t, rctLeaf4, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
|
require.Equal(t, mocks.ExpectedPostState3, postState)
|
||||||
case rct5CID.String():
|
case rct5CID.String():
|
||||||
test_helpers.ExpectEqual(t, data, rctLeaf5)
|
require.Equal(t, rctLeaf5, data)
|
||||||
var postState string
|
var postState string
|
||||||
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
err = db.Get(context.Background(), &postState, postStatePgStr, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
|
require.Equal(t, mocks.ExpectedPostState3, postState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -402,7 +406,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(stateNodes), 2)
|
require.Equal(t, 2, len(stateNodes))
|
||||||
for _, stateNode := range stateNodes {
|
for _, stateNode := range stateNodes {
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(stateNode.CID)
|
dc, err := cid.Decode(stateNode.CID)
|
||||||
@ -411,7 +415,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -422,32 +426,34 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if stateNode.CID == state1CID.String() {
|
if stateNode.CID == state1CID.String() {
|
||||||
test_helpers.ExpectEqual(t, stateNode.NodeType, 2)
|
require.Equal(t, 2, stateNode.NodeType)
|
||||||
test_helpers.ExpectEqual(t, stateNode.StateKey, common.BytesToHash(mocks.ContractLeafKey).Hex())
|
require.Equal(t, common.BytesToHash(mocks.ContractLeafKey).Hex(), stateNode.StateKey)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x06'})
|
require.Equal(t, []byte{'\x06'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, mocks.ContractLeafNode)
|
require.Equal(t, mocks.ContractLeafNode, data)
|
||||||
test_helpers.ExpectEqual(t, account, models.StateAccountModel{
|
require.Equal(t, models.StateAccountModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
HeaderID: account.HeaderID,
|
HeaderID: account.HeaderID,
|
||||||
StatePath: stateNode.Path,
|
StatePath: stateNode.Path,
|
||||||
Balance: "0",
|
Balance: "0",
|
||||||
CodeHash: mocks.ContractCodeHash.Bytes(),
|
CodeHash: mocks.ContractCodeHash.Bytes(),
|
||||||
StorageRoot: mocks.ContractRoot,
|
StorageRoot: mocks.ContractRoot,
|
||||||
Nonce: 1,
|
Nonce: 1,
|
||||||
})
|
}, account)
|
||||||
}
|
}
|
||||||
if stateNode.CID == state2CID.String() {
|
if stateNode.CID == state2CID.String() {
|
||||||
test_helpers.ExpectEqual(t, stateNode.NodeType, 2)
|
require.Equal(t, 2, stateNode.NodeType)
|
||||||
test_helpers.ExpectEqual(t, stateNode.StateKey, common.BytesToHash(mocks.AccountLeafKey).Hex())
|
require.Equal(t, common.BytesToHash(mocks.AccountLeafKey).Hex(), stateNode.StateKey)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x0c'})
|
require.Equal(t, []byte{'\x0c'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, mocks.AccountLeafNode)
|
require.Equal(t, mocks.AccountLeafNode, data)
|
||||||
test_helpers.ExpectEqual(t, account, models.StateAccountModel{
|
require.Equal(t, models.StateAccountModel{
|
||||||
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
HeaderID: account.HeaderID,
|
HeaderID: account.HeaderID,
|
||||||
StatePath: stateNode.Path,
|
StatePath: stateNode.Path,
|
||||||
Balance: "1000",
|
Balance: "1000",
|
||||||
CodeHash: mocks.AccountCodeHash.Bytes(),
|
CodeHash: mocks.AccountCodeHash.Bytes(),
|
||||||
StorageRoot: mocks.AccountRoot,
|
StorageRoot: mocks.AccountRoot,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
})
|
}, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,7 +466,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(stateNodes), 1)
|
require.Equal(t, 1, len(stateNodes))
|
||||||
stateNode := stateNodes[0]
|
stateNode := stateNodes[0]
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(stateNode.CID)
|
dc, err := cid.Decode(stateNode.CID)
|
||||||
@ -469,14 +475,14 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
test_helpers.ExpectEqual(t, prefixedKey, shared.RemovedNodeMhKey)
|
require.Equal(t, shared.RemovedNodeMhKey, prefixedKey)
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, stateNode.CID, shared.RemovedNodeStateCID)
|
require.Equal(t, shared.RemovedNodeStateCID, stateNode.CID)
|
||||||
test_helpers.ExpectEqual(t, stateNode.Path, []byte{'\x02'})
|
require.Equal(t, []byte{'\x02'}, stateNode.Path)
|
||||||
test_helpers.ExpectEqual(t, data, []byte{})
|
require.Equal(t, []byte{}, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Publish and index storage IPLDs in a single tx", func(t *testing.T) {
|
t.Run("Publish and index storage IPLDs in a single tx", func(t *testing.T) {
|
||||||
@ -485,7 +491,7 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
defer checkTxClosure(t, 0, 0, 0)
|
defer checkTxClosure(t, 0, 0, 0)
|
||||||
// check that storage nodes were properly indexed
|
// check that storage nodes were properly indexed
|
||||||
storageNodes := make([]models.StorageNodeWithStateKeyModel, 0)
|
storageNodes := make([]models.StorageNodeWithStateKeyModel, 0)
|
||||||
pgStr := `SELECT storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
pgStr := `SELECT cast(storage_cids.block_number AS TEXT), storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
||||||
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
||||||
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
||||||
AND state_cids.header_id = header_cids.block_hash
|
AND state_cids.header_id = header_cids.block_hash
|
||||||
@ -495,14 +501,15 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(storageNodes), 1)
|
require.Equal(t, 1, len(storageNodes))
|
||||||
test_helpers.ExpectEqual(t, storageNodes[0], models.StorageNodeWithStateKeyModel{
|
require.Equal(t, models.StorageNodeWithStateKeyModel{
|
||||||
CID: storageCID.String(),
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
NodeType: 2,
|
CID: storageCID.String(),
|
||||||
StorageKey: common.BytesToHash(mocks.StorageLeafKey).Hex(),
|
NodeType: 2,
|
||||||
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
StorageKey: common.BytesToHash(mocks.StorageLeafKey).Hex(),
|
||||||
Path: []byte{},
|
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
||||||
})
|
Path: []byte{},
|
||||||
|
}, storageNodes[0])
|
||||||
var data []byte
|
var data []byte
|
||||||
dc, err := cid.Decode(storageNodes[0].CID)
|
dc, err := cid.Decode(storageNodes[0].CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -510,15 +517,15 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
mhKey := dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey := blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, mocks.StorageLeafNode)
|
require.Equal(t, mocks.StorageLeafNode, data)
|
||||||
|
|
||||||
// check that Removed storage nodes were properly indexed
|
// check that Removed storage nodes were properly indexed
|
||||||
storageNodes = make([]models.StorageNodeWithStateKeyModel, 0)
|
storageNodes = make([]models.StorageNodeWithStateKeyModel, 0)
|
||||||
pgStr = `SELECT storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
pgStr = `SELECT cast(storage_cids.block_number AS TEXT), storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path
|
||||||
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
FROM eth.storage_cids, eth.state_cids, eth.header_cids
|
||||||
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
WHERE (storage_cids.state_path, storage_cids.header_id) = (state_cids.state_path, state_cids.header_id)
|
||||||
AND state_cids.header_id = header_cids.block_hash
|
AND state_cids.header_id = header_cids.block_hash
|
||||||
@ -528,25 +535,26 @@ func TestSQLXIndexer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, len(storageNodes), 1)
|
require.Equal(t, 1, len(storageNodes))
|
||||||
test_helpers.ExpectEqual(t, storageNodes[0], models.StorageNodeWithStateKeyModel{
|
require.Equal(t, models.StorageNodeWithStateKeyModel{
|
||||||
CID: shared.RemovedNodeStorageCID,
|
BlockNumber: mocks.BlockNumber.String(),
|
||||||
NodeType: 3,
|
CID: shared.RemovedNodeStorageCID,
|
||||||
StorageKey: common.BytesToHash(mocks.RemovedLeafKey).Hex(),
|
NodeType: 3,
|
||||||
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
StorageKey: common.BytesToHash(mocks.RemovedLeafKey).Hex(),
|
||||||
Path: []byte{'\x03'},
|
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),
|
||||||
})
|
Path: []byte{'\x03'},
|
||||||
|
}, storageNodes[0])
|
||||||
dc, err = cid.Decode(storageNodes[0].CID)
|
dc, err = cid.Decode(storageNodes[0].CID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
mhKey = dshelp.MultihashToDsKey(dc.Hash())
|
mhKey = dshelp.MultihashToDsKey(dc.Hash())
|
||||||
prefixedKey = blockstore.BlockPrefix.String() + mhKey.String()
|
prefixedKey = blockstore.BlockPrefix.String() + mhKey.String()
|
||||||
test_helpers.ExpectEqual(t, prefixedKey, shared.RemovedNodeMhKey)
|
require.Equal(t, shared.RemovedNodeMhKey, prefixedKey)
|
||||||
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey)
|
err = db.Get(context.Background(), &data, ipfsPgGet, prefixedKey, mocks.BlockNumber.Uint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
test_helpers.ExpectEqual(t, data, []byte{})
|
require.Equal(t, []byte{}, data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -106,10 +106,12 @@ var (
|
|||||||
StorageKeys: []common.Hash{common.BytesToHash(StorageLeafKey), common.BytesToHash(MockStorageLeafKey)},
|
StorageKeys: []common.Hash{common.BytesToHash(StorageLeafKey), common.BytesToHash(MockStorageLeafKey)},
|
||||||
}
|
}
|
||||||
AccessListEntry1Model = models.AccessListElementModel{
|
AccessListEntry1Model = models.AccessListElementModel{
|
||||||
Index: 0,
|
BlockNumber: BlockNumber.String(),
|
||||||
Address: Address.Hex(),
|
Index: 0,
|
||||||
|
Address: Address.Hex(),
|
||||||
}
|
}
|
||||||
AccessListEntry2Model = models.AccessListElementModel{
|
AccessListEntry2Model = models.AccessListElementModel{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Index: 1,
|
Index: 1,
|
||||||
Address: AnotherAddress.Hex(),
|
Address: AnotherAddress.Hex(),
|
||||||
StorageKeys: []string{common.BytesToHash(StorageLeafKey).Hex(), common.BytesToHash(MockStorageLeafKey).Hex()},
|
StorageKeys: []string{common.BytesToHash(StorageLeafKey).Hex(), common.BytesToHash(MockStorageLeafKey).Hex()},
|
||||||
|
@ -16,18 +16,6 @@
|
|||||||
|
|
||||||
package test_helpers
|
package test_helpers
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ExpectEqual asserts the provided interfaces are deep equal
|
|
||||||
func ExpectEqual(t *testing.T, got interface{}, want interface{}) {
|
|
||||||
if !reflect.DeepEqual(got, want) {
|
|
||||||
t.Fatalf("Expected: %v\nActual: %v", want, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListContainsString used to check if a list of strings contains a particular string
|
// ListContainsString used to check if a list of strings contains a particular string
|
||||||
func ListContainsString(sss []string, s string) bool {
|
func ListContainsString(sss []string, s string) bool {
|
||||||
for _, str := range sss {
|
for _, str := range sss {
|
||||||
|
Loading…
Reference in New Issue
Block a user