Skip to content

Commit

Permalink
Remove explicit setting default connector.blockchain.rpc
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Semenyuk <[email protected]>
  • Loading branch information
alex-semenyuk committed Jan 11, 2024
1 parent f060841 commit df2fe75
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 46 deletions.
58 changes: 14 additions & 44 deletions cmd/tezosconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,45 @@ package cmd

import (
"context"
"os"
"testing"
"time"

"github.com/hyperledger/firefly-common/pkg/config"
"github.com/hyperledger/firefly-tezosconnect/internal/tezos"
"github.com/stretchr/testify/assert"
)

func TestRun(t *testing.T) {
InitConfig()
testCases := []struct {
name string
errMsg string
initFunc func()
cleanupFunc func()
name string
errMsg string
cfgFile string
}{
{
name: "success",
initFunc: func() {
f, err := os.Create("firefly.tezosconnect")
assert.NoError(t, err)
err = f.Close()
assert.NoError(t, err)

dir, err := os.MkdirTemp("", "ldb_*")
assert.NoError(t, err)
config.Set("persistence.leveldb.path", dir)
},
cleanupFunc: func() {
err := os.Remove("firefly.tezosconnect")
assert.NoError(t, err)
},
name: "success",
cfgFile: "../test/firefly.tezosconnect.yaml",
},
{
name: "error on config not found",
initFunc: func() {},
cleanupFunc: func() {},
errMsg: "FF00101: Failed to read config: Config File \"firefly.tezosconnect\" Not Found",
name: "error on config not found",
cfgFile: "../test/missing.firefly.tezosconnect.yaml",
errMsg: "FF00101: Failed to read config: open ../test/missing.firefly.tezosconnect.yaml: no such file or directory",
},
{
name: "error on NewTezosConnector",
initFunc: func() {
f, err := os.Create("firefly.tezosconnect")
assert.NoError(t, err)
err = f.Close()
assert.NoError(t, err)

connectorConfig.Set(tezos.TxCacheSize, "-1")
},
cleanupFunc: func() {
err := os.Remove("firefly.tezosconnect")
assert.NoError(t, err)
},
errMsg: "FF23040: Failed to initialize transaction cache: Must provide a positive size",
name: "error on NewTezosConnector",
cfgFile: "../test/firefly.tezosconnect-without-connector.yaml",
errMsg: "FF23051: Blockchain RPC node URL must be set",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.initFunc()
cfgFile = tc.cfgFile
ctx, cancelCtx := context.WithTimeout(context.Background(), time.Second)

err := run(ctx, cancelCtx)

tc.cleanupFunc()

if tc.errMsg != "" {
assert.Error(t, err)
assert.Contains(t, err.Error(), tc.errMsg)
assert.Regexp(t, "FF23011", err)
} else {
assert.NoError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion config.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
|Key|Description|Type|Default Value|
|---|-----------|----|-------------|
|network|Tezos network, by default - mainnet (mainnet | ghostnet | nairobinet)|string|`mainnet`
|rpc|URL of the Tezos RPC node|string|`https://rpc.tzstats.com`
|rpc|URL of the Tezos RPC node|string|`<nil>`
|signatory|URL of the signatory service for remote tx signing|string|`<nil>`

## connector.events
Expand Down
2 changes: 1 addition & 1 deletion internal/tezos/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func InitConfig(conf config.Section) {
conf.AddKnownKey(RetryInitDelay, DefaultRetryInitDelay)
conf.AddKnownKey(RetryMaxDelay, DefaultRetryMaxDelay)
conf.AddKnownKey(TxCacheSize, 250)
conf.AddKnownKey(BlockchainRPC, "https://rpc.tzstats.com")
conf.AddKnownKey(BlockchainRPC)
conf.AddKnownKey(BlockchainNetwork, "mainnet")
conf.AddKnownKey(BlockchainSignatory)
}
1 change: 1 addition & 0 deletions internal/tezos/tezos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func newTestConnector(t *testing.T) (context.Context, *tezosConnector, *tzrpcbac
config.RootConfigReset()
conf := config.RootSection("unittest")
InitConfig(conf)
conf.AddKnownKey(BlockchainRPC, "https://ghostnet.example.com")
logrus.SetLevel(logrus.DebugLevel)
ctx, done := context.WithCancel(context.Background())
cc, err := NewTezosConnector(ctx, conf)
Expand Down
3 changes: 3 additions & 0 deletions test/firefly.tezosconnect-without-connector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
persistence:
leveldb:
path: ./.leveldb
6 changes: 6 additions & 0 deletions test/firefly.tezosconnect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
connector:
blockchain:
rpc: https://ghostnet.example.com
persistence:
leveldb:
path: ./.leveldb

0 comments on commit df2fe75

Please sign in to comment.