Skip to content

Commit

Permalink
add helper func
Browse files Browse the repository at this point in the history
Signed-off-by: Borja Aranda <borja.aranda@smartcontract.com>
  • Loading branch information
Borja Aranda committed Mar 18, 2024
1 parent db3596b commit b27ba5a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 48 deletions.
20 changes: 2 additions & 18 deletions pkg/timelock/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import (
)

func Test_isOperation(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}
testWorker := newTestTimelockWorker(t, testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

var ctx context.Context

Expand Down Expand Up @@ -58,11 +54,7 @@ func Test_isOperation(t *testing.T) {
}

func Test_isReady(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}
testWorker := newTestTimelockWorker(t, testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

var ctx context.Context

Expand Down Expand Up @@ -107,10 +99,6 @@ func Test_isReady(t *testing.T) {
func Test_isDone(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}

var ctx context.Context

type args struct {
Expand Down Expand Up @@ -154,10 +142,6 @@ func Test_isDone(t *testing.T) {
func Test_isPending(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}

var ctx context.Context

type args struct {
Expand Down
24 changes: 4 additions & 20 deletions pkg/timelock/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ func Test_newScheduler(t *testing.T) {
}

func TestWorker_updateSchedulerDelay(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}
testWorker := newTestTimelockWorker(t, testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

// Should never fail
testWorker.updateSchedulerDelay(1 * time.Second)
Expand All @@ -58,11 +54,7 @@ func TestWorker_updateSchedulerDelay(t *testing.T) {
}

func TestWorker_isSchedulerBusy(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}
testWorker := newTestTimelockWorker(t, testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

isBusy := testWorker.isSchedulerBusy()
assert.Equal(t, false, isBusy, "scheduler should be busy by default")
Expand All @@ -77,23 +69,15 @@ func TestWorker_isSchedulerBusy(t *testing.T) {
}

func TestWorker_setSchedulerBusy(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}
testWorker := newTestTimelockWorker(t, testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

testWorker.setSchedulerBusy()
isBusy := testWorker.isSchedulerBusy()
assert.Equal(t, true, isBusy, "scheduler should be busy after setSchedulerBusy()")
}

func TestWorker_setSchedulerFree(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}
testWorker := newTestTimelockWorker(t, testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

testWorker.setSchedulerFree()
isBusy := testWorker.isSchedulerBusy()
Expand Down
28 changes: 18 additions & 10 deletions pkg/timelock/timelock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ import (
"github.com/stretchr/testify/assert"
)

func TestNewTimelockWorker(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)
func newTestTimelockWorker(t *testing.T, nodeURL, timelockAddress, callProxyAddress, privateKey string, fromBlock *big.Int, pollPeriod int64, logger *zerolog.Logger) *Worker {
assert.NotEmpty(t, nodeURL, "nodeURL is empty. Are environment variabes in const_test.go set?")
assert.NotEmpty(t, timelockAddress, "nodeURL is empty. Are environment variabes in const_test.go set?")
assert.NotEmpty(t, callProxyAddress, "callProxyAddress is empty. Are environment variabes in const_test.go set?")
assert.NotEmpty(t, privateKey, "privateKey is empty. Are environment variabes in const_test.go set?")
assert.NotNil(t, fromBlock, "fromBlock is nil. Are environment variabes in const_test.go set?")
assert.NotEmpty(t, pollPeriod, "pollPeriod is empty. Are environment variabes in const_test.go set?")
assert.NotNil(t, logger, "logger is nil. Are environment variabes in const_test.go set?")

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}
tw, err := NewTimelockWorker(nodeURL, timelockAddress, callProxyAddress, privateKey, fromBlock, pollPeriod, logger)
assert.NoError(t, err)
assert.NotNil(t, tw)

return tw
}

func TestNewTimelockWorker(t *testing.T) {
testWorker := newTestTimelockWorker(t, testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

type args struct {
nodeURL string
Expand Down Expand Up @@ -181,11 +193,7 @@ func Test_handleOSSignal(t *testing.T) {
}

func TestWorker_startLog(t *testing.T) {
testWorker, _ := NewTimelockWorker(testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

if testWorker == nil {
t.Skipf("testWorker is nil, are the env variables in const_test.go set?")
}
testWorker := newTestTimelockWorker(t, testNodeURL, testTimelockAddress, testCallProxyAddress, testPrivateKey, testFromBlock, int64(testPollPeriod), testLogger)

tests := []struct {
name string
Expand Down

0 comments on commit b27ba5a

Please sign in to comment.