Skip to content

Commit

Permalink
Merge pull request #31 from alex-semenyuk/remove_blockchain_rpc
Browse files Browse the repository at this point in the history
Remove explicit setting default connector.blockchain.rpc at code
  • Loading branch information
denisandreenko committed Jan 12, 2024
2 parents f060841 + 1601a77 commit e5d6d00
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 45 deletions.
56 changes: 13 additions & 43 deletions cmd/tezosconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,42 @@ 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",
},
{
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",
},
}

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)
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 e5d6d00

Please sign in to comment.