Skip to content

Commit

Permalink
Network test: local network QoL
Browse files Browse the repository at this point in the history
  • Loading branch information
BedrockSquirrel committed Feb 27, 2024
1 parent 7049486 commit 11eb799
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
21 changes: 16 additions & 5 deletions integration/networktest/actions/setup_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/integration"
"github.com/ten-protocol/go-ten/integration/common/testlog"
"github.com/ten-protocol/go-ten/integration/datagenerator"
Expand Down Expand Up @@ -45,20 +46,30 @@ func (c *CreateTestUser) Verify(_ context.Context, _ networktest.NetworkConnecto
return nil
}

// AllocateFaucetFunds is an action that allocates funds from the network faucet to a user,
// either UserID or Account must be set (not both) to fund a test user or a specific account respectively
type AllocateFaucetFunds struct {
UserID int
UserID int
Account *common.Address
}

func (a *AllocateFaucetFunds) String() string {
return fmt.Sprintf("AllocateFaucetFunds [user: %d]", a.UserID)
}

func (a *AllocateFaucetFunds) Run(ctx context.Context, network networktest.NetworkConnector) (context.Context, error) {
user, err := FetchTestUser(ctx, a.UserID)
if err != nil {
return ctx, err
var acc common.Address
if a.Account != nil {
acc = *a.Account
} else {
user, err := FetchTestUser(ctx, a.UserID)
if err != nil {
return ctx, err
}
acc = user.Wallet().Address()

Check failure on line 70 in integration/networktest/actions/setup_actions.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
}
return ctx, network.AllocateFaucetFunds(ctx, user.Wallet().Address())
return ctx, network.AllocateFaucetFunds(ctx, acc)
}

func (a *AllocateFaucetFunds) Verify(_ context.Context, _ networktest.NetworkConnector) error {
Expand Down
4 changes: 2 additions & 2 deletions integration/networktest/env/network_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func DevTestnet() networktest.Environment {
// LongRunningLocalNetwork is a local network, the l1WSURL is optional (can be empty string), only required if testing L1 interactions
func LongRunningLocalNetwork(l1WSURL string) networktest.Environment {
connector := NewTestnetConnectorWithFaucetAccount(
"ws://127.0.0.1:37900",
[]string{"ws://127.0.0.1:37901"},
"ws://127.0.0.1:26900",
[]string{"ws://127.0.0.1:26901"},
genesis.TestnetPrefundedPK,
l1WSURL,
"",
Expand Down
2 changes: 1 addition & 1 deletion integration/networktest/env/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/ten-protocol/go-ten/integration/networktest"
)

var _defaultFaucetAmount = big.NewInt(750_000_000_000_000)
var _defaultFaucetAmount = big.NewInt(5_000_000_000_000_000)

type testnetConnector struct {
seqRPCAddress string
Expand Down
23 changes: 23 additions & 0 deletions integration/networktest/tests/helpful/accs_and_contracts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package helpful

import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/integration/networktest"
"github.com/ten-protocol/go-ten/integration/networktest/actions"
"github.com/ten-protocol/go-ten/integration/networktest/env"
)

var _accountToFund = common.HexToAddress("0xD19f62b5A721747A04b969C90062CBb85D4aAaA8")

// Run this test to fund an account with native funds
func TestSendFaucetFunds(t *testing.T) {
networktest.TestOnlyRunsInIDE(t)
networktest.Run(
"send-faucet-funds",
t,
env.LongRunningLocalNetwork(""),
&actions.AllocateFaucetFunds{Account: &_accountToFund},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
func TestRunLocalNetwork(t *testing.T) {
networktest.TestOnlyRunsInIDE(t)
networktest.EnsureTestLogsSetUp("local-geth-network")
networkConnector, cleanUp, err := env.LocalDevNetwork().Prepare()
networkConnector, cleanUp, err := env.LocalDevNetwork(env.WithTenGateway()).Prepare()
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -80,12 +80,19 @@ func checkBalance(walDesc string, wal wallet.Wallet, rpcAddress string) {
}

func keepRunning(networkConnector networktest.NetworkConnector) {
gatewayURL, err := networkConnector.GetGatewayURL()
hasGateway := err == nil

fmt.Println("----")
fmt.Println("Sequencer RPC", networkConnector.SequencerRPCAddress())
for i := 0; i < networkConnector.NumValidators(); i++ {
fmt.Println("Validator ", i, networkConnector.ValidatorRPCAddress(i))
}
if hasGateway {
fmt.Println("Gateway ", gatewayURL)
}
fmt.Println("----")

done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
fmt.Println("Network running until test is stopped...")
Expand Down
1 change: 1 addition & 0 deletions integration/networktest/userwallet/authclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (s *AuthClientUser) SendFunds(ctx context.Context, addr gethcommon.Address,
}

txData := &types.LegacyTx{
Nonce: s.wal.GetNonce(),
Value: value,
To: &addr,
}
Expand Down
2 changes: 1 addition & 1 deletion integration/simulation/devnetwork/dev_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (s *InMemDevNetwork) startTenGateway() {
}
tenGWContainer := container.NewWalletExtensionContainerFromConfig(cfg, s.logger)
go func() {
fmt.Println("Starting Ten Gateway")
fmt.Println("Starting Ten Gateway, HTTP Port:", _gwHTTPPort, "WS Port:", _gwWSPort)
err := tenGWContainer.Start()
if err != nil {
s.logger.Error("failed to start ten gateway", "err", err)
Expand Down

0 comments on commit 11eb799

Please sign in to comment.