From 194cf2b7b15412d0dbea65fc229014ffd6a5c6ad Mon Sep 17 00:00:00 2001 From: David Date: Sun, 29 Oct 2023 18:23:45 +0800 Subject: [PATCH] test: more tests --- prover/proof_producer/dummty_producer_test.go | 53 +++++++++++++++++++ .../proof_producer/guardian_producer_test.go | 51 ++++++++++++++++++ .../optimistic_producer_test.go | 10 ++-- prover/proof_producer/sgx_producer_test.go | 51 ++++++++++++++++++ .../zkevm_rpcd_producer_test.go | 3 ++ 5 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 prover/proof_producer/dummty_producer_test.go create mode 100644 prover/proof_producer/guardian_producer_test.go create mode 100644 prover/proof_producer/sgx_producer_test.go diff --git a/prover/proof_producer/dummty_producer_test.go b/prover/proof_producer/dummty_producer_test.go new file mode 100644 index 000000000..10069f89a --- /dev/null +++ b/prover/proof_producer/dummty_producer_test.go @@ -0,0 +1,53 @@ +package producer + +import ( + "context" + "testing" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" + "github.com/taikoxyz/taiko-client/bindings" +) + +func TestDummyProducerRequestProof(t *testing.T) { + producer := &DummyProofProducer{} + + resCh := make(chan *ProofWithHeader, 1) + + var tier uint16 = 1024 + + blockID := common.Big32 + header := &types.Header{ + ParentHash: randHash(), + UncleHash: randHash(), + Coinbase: common.BytesToAddress(randHash().Bytes()), + Root: randHash(), + TxHash: randHash(), + ReceiptHash: randHash(), + Difficulty: common.Big0, + Number: common.Big256, + GasLimit: 1024, + GasUsed: 1024, + Time: uint64(time.Now().Unix()), + Extra: randHash().Bytes(), + MixDigest: randHash(), + Nonce: types.BlockNonce{}, + } + require.Nil(t, producer.RequestProof( + context.Background(), + &ProofRequestOptions{}, + blockID, + &bindings.TaikoDataBlockMetadata{}, + header, + tier, + resCh, + )) + + res := <-resCh + require.Equal(t, res.BlockID, blockID) + require.Equal(t, res.Header, header) + require.Equal(t, tier, res.Tier) + require.NotEmpty(t, res.Proof) +} diff --git a/prover/proof_producer/guardian_producer_test.go b/prover/proof_producer/guardian_producer_test.go new file mode 100644 index 000000000..e7d541fcb --- /dev/null +++ b/prover/proof_producer/guardian_producer_test.go @@ -0,0 +1,51 @@ +package producer + +import ( + "context" + "testing" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" + "github.com/taikoxyz/taiko-client/bindings" + "github.com/taikoxyz/taiko-client/bindings/encoding" +) + +func TestGuardianProducerRequestProof(t *testing.T) { + producer := &GuardianProofProducer{} + + resCh := make(chan *ProofWithHeader, 1) + + blockID := common.Big32 + header := &types.Header{ + ParentHash: randHash(), + UncleHash: randHash(), + Coinbase: common.BytesToAddress(randHash().Bytes()), + Root: randHash(), + TxHash: randHash(), + ReceiptHash: randHash(), + Difficulty: common.Big0, + Number: common.Big256, + GasLimit: 1024, + GasUsed: 1024, + Time: uint64(time.Now().Unix()), + Extra: randHash().Bytes(), + MixDigest: randHash(), + Nonce: types.BlockNonce{}, + } + require.Nil(t, producer.RequestProof( + context.Background(), + &ProofRequestOptions{}, + blockID, + &bindings.TaikoDataBlockMetadata{}, + header, + resCh, + )) + + res := <-resCh + require.Equal(t, res.BlockID, blockID) + require.Equal(t, res.Header, header) + require.Equal(t, res.Tier, encoding.TierGuardianID) + require.NotEmpty(t, res.Proof) +} diff --git a/prover/proof_producer/optimistic_producer_test.go b/prover/proof_producer/optimistic_producer_test.go index 8a4663c90..024358fd0 100644 --- a/prover/proof_producer/optimistic_producer_test.go +++ b/prover/proof_producer/optimistic_producer_test.go @@ -11,10 +11,11 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/stretchr/testify/require" "github.com/taikoxyz/taiko-client/bindings" + "github.com/taikoxyz/taiko-client/bindings/encoding" ) -func TestRequestProof(t *testing.T) { - optimisticProofProducer := &OptimisticProofProducer{} +func TestOptimisticRequestProof(t *testing.T) { + producer := &OptimisticProofProducer{} resCh := make(chan *ProofWithHeader, 1) @@ -22,7 +23,7 @@ func TestRequestProof(t *testing.T) { header := &types.Header{ ParentHash: randHash(), UncleHash: randHash(), - Coinbase: common.HexToAddress("0x0000777735367b36bC9B61C50022d9D0700dB4Ec"), + Coinbase: common.BytesToAddress(randHash().Bytes()), Root: randHash(), TxHash: randHash(), ReceiptHash: randHash(), @@ -35,7 +36,7 @@ func TestRequestProof(t *testing.T) { MixDigest: randHash(), Nonce: types.BlockNonce{}, } - require.Nil(t, optimisticProofProducer.RequestProof( + require.Nil(t, producer.RequestProof( context.Background(), &ProofRequestOptions{}, blockID, @@ -47,6 +48,7 @@ func TestRequestProof(t *testing.T) { res := <-resCh require.Equal(t, res.BlockID, blockID) require.Equal(t, res.Header, header) + require.Equal(t, res.Tier, encoding.TierOptimisticID) require.NotEmpty(t, res.Proof) } diff --git a/prover/proof_producer/sgx_producer_test.go b/prover/proof_producer/sgx_producer_test.go new file mode 100644 index 000000000..14adcf36e --- /dev/null +++ b/prover/proof_producer/sgx_producer_test.go @@ -0,0 +1,51 @@ +package producer + +import ( + "context" + "testing" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" + "github.com/taikoxyz/taiko-client/bindings" + "github.com/taikoxyz/taiko-client/bindings/encoding" +) + +func TestSGXProducerRequestProof(t *testing.T) { + producer := &SGXProofProducer{} + + resCh := make(chan *ProofWithHeader, 1) + + blockID := common.Big32 + header := &types.Header{ + ParentHash: randHash(), + UncleHash: randHash(), + Coinbase: common.BytesToAddress(randHash().Bytes()), + Root: randHash(), + TxHash: randHash(), + ReceiptHash: randHash(), + Difficulty: common.Big0, + Number: common.Big256, + GasLimit: 1024, + GasUsed: 1024, + Time: uint64(time.Now().Unix()), + Extra: randHash().Bytes(), + MixDigest: randHash(), + Nonce: types.BlockNonce{}, + } + require.Nil(t, producer.RequestProof( + context.Background(), + &ProofRequestOptions{}, + blockID, + &bindings.TaikoDataBlockMetadata{}, + header, + resCh, + )) + + res := <-resCh + require.Equal(t, res.BlockID, blockID) + require.Equal(t, res.Header, header) + require.Equal(t, res.Tier, encoding.TierSgxID) + require.NotEmpty(t, res.Proof) +} diff --git a/prover/proof_producer/zkevm_rpcd_producer_test.go b/prover/proof_producer/zkevm_rpcd_producer_test.go index 87ae7af1d..2f0bcbba0 100644 --- a/prover/proof_producer/zkevm_rpcd_producer_test.go +++ b/prover/proof_producer/zkevm_rpcd_producer_test.go @@ -21,6 +21,7 @@ func TestNewZkevmRpcdProducer(t *testing.T) { &bindings.TaikoDataConfig{}, ) require.Nil(t, err) + require.False(t, dummyZkevmRpcdProducer.Cancellable()) dummyZkevmRpcdProducer.CustomProofHook = func() ([]byte, uint64, error) { return []byte{0}, CircuitsIdx, nil @@ -59,4 +60,6 @@ func TestNewZkevmRpcdProducer(t *testing.T) { require.Equal(t, res.BlockID, blockID) require.Equal(t, res.Header, header) require.NotEmpty(t, res.Proof) + + require.Nil(t, dummyZkevmRpcdProducer.Cancel(context.Background(), common.Big1)) }