Skip to content

Commit

Permalink
Segregate integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisPH3 committed Dec 2, 2024
1 parent ec3be9d commit 8bbae9e
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tests
package address_access_test

import (
"math/big"
"testing"

"github.com/Fantom-foundation/go-opera/tests"
accessCost "github.com/Fantom-foundation/go-opera/tests/contracts/access_cost"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -13,13 +14,13 @@ import (
func TestAddressAccess(t *testing.T) {
someAccountAddress := common.Address{1}

net, err := StartIntegrationTestNet(t.TempDir())
net, err := tests.StartIntegrationTestNet(t.TempDir())
if err != nil {
t.Fatalf("Failed to start the fake network: %v", err)
}
defer net.Stop()

contract, receipt, err := DeployContract(net, accessCost.DeployAccessCost)
contract, receipt, err := tests.DeployContract(net, accessCost.DeployAccessCost)
checkTxExecution(t, receipt, err)

// Execute function on an address, cold access
Expand Down
7 changes: 4 additions & 3 deletions tests/basefee_test.go → tests/basefee/basefee_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package tests
package basefee_test

import (
"context"
"testing"

"github.com/Fantom-foundation/go-opera/tests"
"github.com/Fantom-foundation/go-opera/tests/contracts/basefee"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
)

func TestBaseFee_CanReadBaseFeeFromHeadAndBlockAndHistory(t *testing.T) {
net, err := StartIntegrationTestNet(t.TempDir())
net, err := tests.StartIntegrationTestNet(t.TempDir())
if err != nil {
t.Fatalf("Failed to start the fake network: %v", err)
}
defer net.Stop()

// Deploy the base fee contract.
contract, _, err := DeployContract(net, basefee.DeployBasefee)
contract, _, err := tests.DeployContract(net, basefee.DeployBasefee)
if err != nil {
t.Fatalf("failed to deploy contract; %v", err)
}
Expand Down
15 changes: 8 additions & 7 deletions tests/blob_tx_test.go → tests/blob_tx/blob_tx_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package tests
package blob_tx_test

import (
"context"
"math/big"
"testing"

"github.com/Fantom-foundation/go-opera/tests"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
Expand Down Expand Up @@ -106,7 +107,7 @@ func createTestBlobTransaction(t *testing.T, ctxt *testContext, data ...[]byte)
chainId, err := ctxt.client.ChainID(context.Background())
require.NoError(err, "failed to get chain ID::")

nonce, err := ctxt.client.NonceAt(context.Background(), ctxt.net.validator.Address(), nil)
nonce, err := ctxt.client.NonceAt(context.Background(), ctxt.net.GetValidatorAccount().Address(), nil)
require.NoError(err, "failed to get nonce:")

var sidecar *types.BlobTxSidecar
Expand Down Expand Up @@ -150,7 +151,7 @@ func createTestBlobTransaction(t *testing.T, ctxt *testContext, data ...[]byte)
Sidecar: sidecar, // sidecar data in the transaction
})

return types.SignTx(tx, types.NewCancunSigner(chainId), ctxt.net.validator.PrivateKey)
return types.SignTx(tx, types.NewCancunSigner(chainId), ctxt.net.GetValidatorAccount().PrivateKey)
}

func createTestBlobTransactionWithNilSidecar(t *testing.T, ctxt *testContext) (*types.Transaction, error) {
Expand All @@ -159,7 +160,7 @@ func createTestBlobTransactionWithNilSidecar(t *testing.T, ctxt *testContext) (*
chainId, err := ctxt.client.ChainID(context.Background())
require.NoError(err, "failed to get chain ID::")

nonce, err := ctxt.client.NonceAt(context.Background(), ctxt.net.validator.Address(), nil)
nonce, err := ctxt.client.NonceAt(context.Background(), ctxt.net.GetValidatorAccount().Address(), nil)
require.NoError(err, "failed to get nonce:")

// Create and return transaction with the blob data and cryptographic proofs
Expand All @@ -176,7 +177,7 @@ func createTestBlobTransactionWithNilSidecar(t *testing.T, ctxt *testContext) (*
Sidecar: nil, // sidecar data in the transaction
})

return types.SignTx(tx, types.NewCancunSigner(chainId), ctxt.net.validator.PrivateKey)
return types.SignTx(tx, types.NewCancunSigner(chainId), ctxt.net.GetValidatorAccount().PrivateKey)
}

func checkBlocksSanity(t *testing.T, client *ethclient.Client) {
Expand All @@ -194,12 +195,12 @@ func checkBlocksSanity(t *testing.T, client *ethclient.Client) {
}

type testContext struct {
net *IntegrationTestNet
net *tests.IntegrationTestNet
client *ethclient.Client
}

func MakeTestContext(t *testing.T) *testContext {
net, err := StartIntegrationTestNet(t.TempDir())
net, err := tests.StartIntegrationTestNet(t.TempDir())
require.NoError(t, err)

client, err := net.GetClient()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package tests
package blobbasefeee_test

import (
"bytes"
"context"
"testing"

"github.com/Fantom-foundation/go-opera/tests"
"github.com/Fantom-foundation/go-opera/tests/contracts/blobbasefee"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand All @@ -16,12 +17,12 @@ import (

func TestBlobBaseFee_CanReadBlobBaseFeeFromHeadAndBlockAndHistory(t *testing.T) {
require := require.New(t)
net, err := StartIntegrationTestNet(t.TempDir())
net, err := tests.StartIntegrationTestNet(t.TempDir())
require.NoError(err, "Failed to start the fake network: ", err)
defer net.Stop()

// Deploy the blob base fee contract.
contract, _, err := DeployContract(net, blobbasefee.DeployBlobbasefee)
contract, _, err := tests.DeployContract(net, blobbasefee.DeployBlobbasefee)
require.NoError(err, "failed to deploy contract; ", err)

// Collect the current blob base fee from the head state.
Expand Down Expand Up @@ -69,7 +70,7 @@ func getBlobBaseFeeFrom(header *types.Header) uint64 {

func TestBlobBaseFee_CanReadBlobGasUsed(t *testing.T) {
require := require.New(t)
net, err := StartIntegrationTestNet(t.TempDir())
net, err := tests.StartIntegrationTestNet(t.TempDir())
require.NoError(err, "Failed to start the fake network: ", err)
defer net.Stop()

Expand Down
11 changes: 6 additions & 5 deletions tests/block_hash_test.go → tests/block_hash/block_hash_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package tests
package block_has_test

import (
"context"
"math/big"
"testing"

"github.com/Fantom-foundation/go-opera/tests"
"github.com/Fantom-foundation/go-opera/tests/contracts/block_hash"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -14,14 +15,14 @@ import (

func TestBlockHash_CorrectBlockHashesAreAccessibleInContracts(t *testing.T) {
require := req.New(t)
net, err := StartIntegrationTestNet(t.TempDir())
net, err := tests.StartIntegrationTestNet(t.TempDir())
if err != nil {
t.Fatalf("Failed to start the fake network: %v", err)
}
defer net.Stop()

// Deploy the block hash observer contract.
_, receipt, err := DeployContract(net, block_hash.DeployBlockHash)
_, receipt, err := tests.DeployContract(net, block_hash.DeployBlockHash)
require.NoError(err, "failed to deploy contract; %v", err)
contractAddress := receipt.ContractAddress
contractCreationBlock := receipt.BlockNumber.Uint64()
Expand All @@ -44,7 +45,7 @@ func TestBlockHash_CorrectBlockHashesAreAccessibleInContracts(t *testing.T) {

func testVisibleBlockHashOnHead(
t *testing.T,
net *IntegrationTestNet,
net *tests.IntegrationTestNet,
observerContractAddress common.Address,
) {
require := req.New(t)
Expand Down Expand Up @@ -86,7 +87,7 @@ func testVisibleBlockHashOnHead(

func testVisibleBlockHashesInArchive(
t *testing.T,
net *IntegrationTestNet,
net *tests.IntegrationTestNet,
observerContractAddress common.Address,
observerCreationBlock uint64,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package blockheader_test

import (
"cmp"
Expand All @@ -20,6 +20,7 @@ import (
"github.com/Fantom-foundation/go-opera/opera/contracts/evmwriter"
"github.com/Fantom-foundation/go-opera/opera/contracts/netinit"
"github.com/Fantom-foundation/go-opera/opera/contracts/sfc"
"github.com/Fantom-foundation/go-opera/tests"
"github.com/Fantom-foundation/go-opera/tests/contracts/counter_event_emitter"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -35,27 +36,28 @@ import (

func TestBlockHeader_FakeGenesis_SatisfiesInvariants(t *testing.T) {
require := require.New(t)
net, err := StartIntegrationTestNet(t.TempDir())

net, err := tests.StartIntegrationTestNet(t.TempDir())
require.NoError(err)
defer net.Stop()
testBlockHeadersOnNetwork(t, net)
}

func TestBlockHeader_JsonGenesis_SatisfiesInvariants(t *testing.T) {
require := require.New(t)
net, err := StartIntegrationTestNetFromJsonGenesis(t.TempDir())
net, err := tests.StartIntegrationTestNetFromJsonGenesis(t.TempDir())
require.NoError(err)
defer net.Stop()
testBlockHeadersOnNetwork(t, net)
}

func testBlockHeadersOnNetwork(t *testing.T, net *IntegrationTestNet) {
func testBlockHeadersOnNetwork(t *testing.T, net *tests.IntegrationTestNet) {
const numBlocks = 10
require := require.New(t)

// Produce a few blocks on the network. We use the counter contract since
// it is also producing events.
counter, receipt, err := DeployContract(net, counter_event_emitter.DeployCounterEventEmitter)
counter, receipt, err := tests.DeployContract(net, counter_event_emitter.DeployCounterEventEmitter)
require.NoError(err)
for range numBlocks {
_, err := net.Apply(counter.Increment)
Expand Down
11 changes: 6 additions & 5 deletions tests/counter_test.go → tests/counter/counter_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package tests
package counter_test

import (
"math"
"math/big"
"testing"

"github.com/Fantom-foundation/go-opera/tests"
"github.com/Fantom-foundation/go-opera/tests/contracts/counter"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
)

func TestCounter_CanIncrementAndReadCounterFromHead(t *testing.T) {
net, err := StartIntegrationTestNet(t.TempDir())
net, err := tests.StartIntegrationTestNet(t.TempDir())
if err != nil {
t.Fatalf("Failed to start the fake network: %v", err)
}
defer net.Stop()

// Deploy the counter contract.
contract, _, err := DeployContract(net, counter.DeployCounter)
contract, _, err := tests.DeployContract(net, counter.DeployCounter)
if err != nil {
t.Fatalf("failed to deploy contract; %v", err)
}
Expand All @@ -41,14 +42,14 @@ func TestCounter_CanIncrementAndReadCounterFromHead(t *testing.T) {
}

func TestCounter_CanReadHistoricCounterValues(t *testing.T) {
net, err := StartIntegrationTestNet(t.TempDir())
net, err := tests.StartIntegrationTestNet(t.TempDir())
if err != nil {
t.Fatalf("Failed to start the fake network: %v", err)
}
defer net.Stop()

// Deploy the counter contract.
contract, receipt, err := DeployContract(net, counter.DeployCounter)
contract, receipt, err := tests.DeployContract(net, counter.DeployCounter)
if err != nil {
t.Fatalf("failed to deploy contract; %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tests
package gas_price_suggestion

import (
"context"
"crypto/ecdsa"
"math/big"
"testing"

"github.com/Fantom-foundation/go-opera/tests"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -55,11 +56,11 @@ func TestGasPrice_UnderpricedTransactionsAreRejected(t *testing.T) {
chainId, err := client.ChainID(context.Background())
require.NoError(err, "failed to get chain ID::")

nonce, err := client.NonceAt(context.Background(), net.validator.Address(), nil)
nonce, err := client.NonceAt(context.Background(), net.GetValidatorAccount().Address(), nil)
require.NoError(err, "failed to get nonce:")

factory := &txFactory{
senderKey: net.validator.PrivateKey,
senderKey: net.GetValidatorAccount().PrivateKey,
chainId: chainId,
}

Expand Down Expand Up @@ -92,8 +93,8 @@ func TestGasPrice_UnderpricedTransactionsAreRejected(t *testing.T) {
require.NoError(send(factory.makeBlobTransactionWithPrice(t, nonce+3, feeCap)))
}

func makeNetAndClient(t *testing.T) (*IntegrationTestNet, *ethclient.Client) {
net, err := StartIntegrationTestNet(t.TempDir())
func makeNetAndClient(t *testing.T) (*tests.IntegrationTestNet, *ethclient.Client) {
net, err := tests.StartIntegrationTestNet(t.TempDir())
require.NoError(t, err)
t.Cleanup(func() { net.Stop() })

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tests
package genesis_import_test

import (
"context"
"testing"

"github.com/Fantom-foundation/go-opera/tests"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
Expand All @@ -13,7 +14,7 @@ func TestGenesis_NetworkCanCreateNewBlocksAfterExportImport(t *testing.T) {
require := require.New(t)

tempDir := t.TempDir()
net, err := StartIntegrationTestNet(tempDir)
net, err := tests.StartIntegrationTestNet(tempDir)
require.NoError(err)

// Produce a few blocks on the network.
Expand Down
Loading

0 comments on commit 8bbae9e

Please sign in to comment.