Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ jobs:
- name: Run tests
run: |
set -euo pipefail
go test -json -v $(go list ./... | grep -Ev '/blockchain|/badgerTrie|/consensus|/transport|/testutils') 2>&1 | tee /tmp/gotest.log | gotestfmt
go test -json -v $(go list ./... | grep -Ev '/badgerTrie|/consensus|/transport|/testutils') 2>&1 | tee /tmp/gotest.log | gotestfmt
45 changes: 43 additions & 2 deletions blockchain/cancellation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestSleepWithContextComplete(t *testing.T) {
assert.True(t, completed)
}

func TestSleepWithContextInterupted(t *testing.T) {
func TestSleepWithContextInterrupted(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())

completed := false
Expand All @@ -48,10 +48,51 @@ func TestSleepWithContextInterupted(t *testing.T) {
}
wg.Done()
}()

cancel()

wg.Wait()

assert.False(t, completed)
}

func TestSlowReturn(t *testing.T) {
ctx, _ := context.WithCancel(context.Background())

type args struct {
ctx context.Context
delay time.Duration
value bool
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Test slow Return success",
args: args{
ctx: ctx,
delay: 5000 * time.Millisecond,
value: true,
},
want: true,
},
{
name: "Test slow Return quicker delay",
args: args{
ctx: ctx,
delay: 500 * time.Millisecond,
value: false,
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
start := time.Now()
assert.Equalf(t, tt.want, blockchain.SlowReturn(tt.args.ctx, tt.args.delay, tt.args.value), "SlowReturn(%v, %v, %v)", tt.args.ctx, tt.args.delay, tt.args.value)
elapsed := time.Since(start)
assert.GreaterOrEqual(t, elapsed, tt.args.delay, "Delay time has not been respected")
})
}
}
84 changes: 0 additions & 84 deletions blockchain/deposit_test.go

This file was deleted.

10 changes: 0 additions & 10 deletions blockchain/ethdkg_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion blockchain/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func NewEthereumEndpoint(
defer cancel()
rpcClient, rpcErr := rpc.DialContext(ctx, endpoint)
if rpcErr != nil {
logger.Errorf("Error in NewEthereumEndpoint at rpc.DialContext: %v", err)
logger.Errorf("Error in NewEthereumEndpoint at rpc.DialContext: %v", rpcErr)
return nil, rpcErr
}
ethClient := ethclient.NewClient(rpcClient)
Expand Down
113 changes: 113 additions & 0 deletions blockchain/ethereum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package blockchain_test

import (
"context"
"errors"
"fmt"
"io/fs"
"math"
"math/big"
"net"
"testing"
"time"

Expand Down Expand Up @@ -92,3 +96,112 @@ func TestHardhatNode(t *testing.T) {

t.Logf("done testing")
}

func TestNewEthereumEndpoint(t *testing.T) {

eth := setupEthereum(t, 4)
defer eth.Close()

type args struct {
endpoint string
pathKeystore string
pathPasscodes string
defaultAccount string
timeout time.Duration
retryCount int
retryDelay time.Duration
finalityDelay int
txFeePercentageToIncrease int
txMaxFeeThresholdInGwei uint64
txCheckFrequency time.Duration
txTimeoutForReplacement time.Duration
}
tests := []struct {
name string
args args
want bool
wantErr assert.ErrorAssertionFunc
}{

{
name: "Create new ethereum endpoint failing with passcode file not found",
args: args{"", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0},
want: false,
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
_, ok := err.(*fs.PathError)
if !ok {
t.Errorf("Failing test with an unexpected error")
}
return ok
},
},
{
name: "Create new ethereum endpoint failing with specified account not found",
args: args{"", "", "../assets/test/passcodes.txt", "", 0, 0, 0, 0, 0, 0, 0, 0},
want: false,
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
if !errors.Is(err, blockchain.ErrAccountNotFound) {
t.Errorf("Failing test with an unexpected error")
}
return true
},
},
{
name: "Create new ethereum endpoint failing on Dial Context",
args: args{
eth.GetEndpoint(),
"../assets/test/keys",
"../assets/test/passcodes.txt",
eth.GetDefaultAccount().Address.String(),
eth.Timeout(),
eth.RetryCount(),
eth.RetryDelay(),
int(eth.GetFinalityDelay()),
eth.GetTxFeePercentageToIncrease(),
eth.GetTxMaxFeeThresholdInGwei(),
eth.GetTxCheckFrequency(),
eth.GetTxTimeoutForReplacement(),
},
want: false,
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
_, ok := err.(*net.OpError)
if !ok {
t.Errorf("Failing test with an unexpected error")
}
return ok
},
},
{
name: "Create new ethereum endpoint returning EthereumDetails",
args: args{
"http://localhost:8545",
"../assets/test/keys",
"../assets/test/passcodes.txt",
eth.GetDefaultAccount().Address.String(),
eth.Timeout(),
eth.RetryCount(),
eth.RetryDelay(),
int(eth.GetFinalityDelay()),
eth.GetTxFeePercentageToIncrease(),
eth.GetTxMaxFeeThresholdInGwei(),
eth.GetTxCheckFrequency(),
eth.GetTxTimeoutForReplacement(),
},
want: true,
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
return true
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := blockchain.NewEthereumEndpoint(tt.args.endpoint, tt.args.pathKeystore, tt.args.pathPasscodes, tt.args.defaultAccount, tt.args.timeout, tt.args.retryCount, tt.args.retryDelay, tt.args.finalityDelay, tt.args.txFeePercentageToIncrease, tt.args.txMaxFeeThresholdInGwei, tt.args.txCheckFrequency, tt.args.txTimeoutForReplacement)
if !tt.wantErr(t, err, fmt.Sprintf("NewEthereumEndpoint(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v)", tt.args.endpoint, tt.args.pathKeystore, tt.args.pathPasscodes, tt.args.defaultAccount, tt.args.timeout, tt.args.retryCount, tt.args.retryDelay, tt.args.finalityDelay, tt.args.txFeePercentageToIncrease, tt.args.txMaxFeeThresholdInGwei, tt.args.txCheckFrequency, tt.args.txTimeoutForReplacement)) {
return
}
if tt.want {
assert.NotNilf(t, got, "Ethereum Details must not be nil")
}
})
}
}
Loading