Skip to content

Commit

Permalink
Reorder gql
Browse files Browse the repository at this point in the history
  • Loading branch information
telackey committed Jul 22, 2023
1 parent 9fce784 commit 21575e2
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions pkg/graphql/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -85,40 +86,63 @@ var _ = BeforeSuite(func() {
// make the test blockchain (and state)
chainConfig.LondonBlock = big.NewInt(100)
blocks, receipts, chain = test_helpers.MakeChain(5, test_helpers.Genesis, test_helpers.TestChainGen, chainConfig)
test_helpers.IndexChain(test_helpers.IndexChainParams{
StateCache: chain.StateCache(),
ChainConfig: chainConfig,
Blocks: blocks,
Receipts: receipts,
TotalDifficulty: mockTD,
})
indexer := shared.SetupTestStateDiffIndexer(context.Background(), chainConfig, test_helpers.Genesis.Hash())
builder := statediff.NewBuilder(chain.StateCache())

// Insert some non-canonical data into the database so that we test our ability to discern canonicity
indexAndPublisher := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())

nonCanonBlockHash = test_helpers.MockBlock.Hash()
nonCanonContractAddress = test_helpers.ContractAddr

tx, err := indexAndPublisher.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
tx, err := indexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
Expect(err).ToNot(HaveOccurred())

err = tx.Submit(err)
Expect(err).ToNot(HaveOccurred())

// The non-canonical header has a child
tx, err = indexAndPublisher.PushBlock(test_helpers.MockChild, test_helpers.MockReceipts, test_helpers.MockChild.Difficulty())
tx, err = indexer.PushBlock(test_helpers.MockChild, test_helpers.MockReceipts, test_helpers.MockChild.Difficulty())
Expect(err).ToNot(HaveOccurred())

ipld := sdtypes.IPLD{
CID: ipld.Keccak256ToCid(ipld.RawBinary, test_helpers.CodeHash.Bytes()).String(),
Content: test_helpers.ContractCode,
}
err = indexAndPublisher.PushIPLD(tx, ipld)
err = indexer.PushIPLD(tx, ipld)
Expect(err).ToNot(HaveOccurred())

err = tx.Submit(err)
Expect(err).ToNot(HaveOccurred())

// iterate over the blocks, generating statediff payloads, and transforming the data into Postgres
for i, block := range blocks {
var args statediff.Args
var rcts types.Receipts
if i == 0 {
args = statediff.Args{
OldStateRoot: common.Hash{},
NewStateRoot: block.Root(),
BlockNumber: block.Number(),
BlockHash: block.Hash(),
}
} else {
args = statediff.Args{
OldStateRoot: blocks[i-1].Root(),
NewStateRoot: block.Root(),
BlockNumber: block.Number(),
BlockHash: block.Hash(),
}
rcts = receipts[i-1]
}

_, err = builder.BuildStateDiffObject(args, statediff.Params{})
Expect(err).ToNot(HaveOccurred())
tx, err := indexer.PushBlock(block, rcts, mockTD)
Expect(err).ToNot(HaveOccurred())

err = tx.Submit(err)
Expect(err).ToNot(HaveOccurred())
}

graphQLServer, err = graphql.New(backend, gqlEndPoint, nil, []string{"*"}, rpc.HTTPTimeouts{})
Expect(err).ToNot(HaveOccurred())

Expand Down

0 comments on commit 21575e2

Please sign in to comment.