Skip to content

Commit

Permalink
Merge pull request #854 from smartcontractkit/chore/integrate_viper
Browse files Browse the repository at this point in the history
Integrate Viper
  • Loading branch information
j16r authored Jan 3, 2019
2 parents fe804d1 + 09c1b2c commit 75c0ec5
Show file tree
Hide file tree
Showing 39 changed files with 611 additions and 333 deletions.
95 changes: 95 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@
[[constraint]]
name = "github.com/golang/mock"
version = "1.2.0"

[[constraint]]
name = "github.com/spf13/viper.git"
version = "1.3.1"
8 changes: 4 additions & 4 deletions adapters/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ func (p PipelineAdapter) MinConfs() uint64 {
}

// MinContractPayment returns the private attribute
func (p PipelineAdapter) MinContractPayment() assets.Link {
return p.minContractPayment
func (p PipelineAdapter) MinContractPayment() *assets.Link {
return &p.minContractPayment
}

// For determines the adapter type to use for a given task.
func For(task models.TaskSpec, store *store.Store) (*PipelineAdapter, error) {
var ba BaseAdapter
var err error
mic := store.Config.MinIncomingConfirmations
mic := store.Config.MinIncomingConfirmations()
mcp := *assets.NewLink(0)

switch task.Type {
Expand All @@ -88,7 +88,7 @@ func For(task models.TaskSpec, store *store.Store) (*PipelineAdapter, error) {
err = unmarshalParams(task.Params, ba)
case TaskTypeEthTx:
ba = &EthTx{}
mcp = store.Config.MinimumContractPayment
mcp = *store.Config.MinimumContractPayment()
err = unmarshalParams(task.Params, ba)
case TaskTypeHTTPGet:
ba = &HTTPGet{}
Expand Down
4 changes: 2 additions & 2 deletions adapters/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestAdapterFor(t *testing.T) {
}{
{"adapter not found", "nonExistent", "<nil>", nil, true},
{"noop", "NoOp", "*adapters.NoOp", assets.NewLink(0), false},
{"ethtx", "EthTx", "*adapters.EthTx", &store.Config.MinimumContractPayment, false},
{"ethtx", "EthTx", "*adapters.EthTx", store.Config.MinimumContractPayment(), false},
{"bridge mixed case", "rideShare", "*adapters.Bridge", assets.NewLink(10), false},
{"bridge lower case", "rideshare", "*adapters.Bridge", assets.NewLink(10), false},
}
Expand All @@ -54,7 +54,7 @@ func TestAdapterFor(t *testing.T) {
} else {
assert.NoError(t, err)
assert.Equal(t, test.wantType, reflect.TypeOf(adapter.BaseAdapter).String())
assert.Equal(t, *test.wantMinContractPayment, adapter.MinContractPayment())
assert.Equal(t, test.wantMinContractPayment, adapter.MinContractPayment())
}
})
}
Expand Down
13 changes: 8 additions & 5 deletions adapters/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"

"github.com/smartcontractkit/chainlink/store"
"github.com/smartcontractkit/chainlink/store/models"
Expand All @@ -30,15 +31,15 @@ func (ba *Bridge) Perform(input models.RunResult, store *store.Store) models.Run
} else if input.Status.PendingBridge() {
return resumeBridge(input)
}
return ba.handleNewRun(input, store.Config.BridgeResponseURL)
return ba.handleNewRun(input, store.Config.BridgeResponseURL())
}

func resumeBridge(input models.RunResult) models.RunResult {
input.Status = models.RunStatusInProgress
return input
}

func (ba *Bridge) handleNewRun(input models.RunResult, bridgeResponseURL models.WebURL) models.RunResult {
func (ba *Bridge) handleNewRun(input models.RunResult, bridgeResponseURL *url.URL) models.RunResult {
var err error
if ba.Params != nil {
input.Data, err = input.Data.Merge(*ba.Params)
Expand All @@ -48,7 +49,7 @@ func (ba *Bridge) handleNewRun(input models.RunResult, bridgeResponseURL models.
}

responseURL := bridgeResponseURL
if (responseURL != models.WebURL{}) {
if *responseURL != *zeroURL {
responseURL.Path += fmt.Sprintf("/v2/runs/%s", input.JobRunID)
}
body, err := ba.postToExternalAdapter(input, responseURL)
Expand All @@ -74,7 +75,7 @@ func responseToRunResult(body []byte, input models.RunResult) models.RunResult {
return rr
}

func (ba *Bridge) postToExternalAdapter(input models.RunResult, bridgeResponseURL models.WebURL) ([]byte, error) {
func (ba *Bridge) postToExternalAdapter(input models.RunResult, bridgeResponseURL *url.URL) ([]byte, error) {
in, err := json.Marshal(&bridgeOutgoing{
RunResult: input,
ResponseURL: bridgeResponseURL,
Expand Down Expand Up @@ -112,7 +113,7 @@ func baRunResultError(in models.RunResult, str string, err error) models.RunResu

type bridgeOutgoing struct {
models.RunResult
ResponseURL models.WebURL
ResponseURL *url.URL
}

func (bp bridgeOutgoing) MarshalJSON() ([]byte, error) {
Expand All @@ -127,3 +128,5 @@ func (bp bridgeOutgoing) MarshalJSON() ([]byte, error) {
}
return json.Marshal(anon)
}

var zeroURL = new(url.URL)
8 changes: 4 additions & 4 deletions adapters/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestBridge_PerformEmbedsParamsInData(t *testing.T) {
store, cleanup := cltest.NewStore()
defer cleanup()
store.Config.BridgeResponseURL = cltest.WebURL("")
store.Config.Set("BridgeResponseURL", cltest.WebURL(""))

data := ""
token := ""
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestBridge_Perform_transitionsTo(t *testing.T) {

store, cleanup := cltest.NewStore()
defer cleanup()
store.Config.BridgeResponseURL = cltest.WebURL("")
store.Config.Set("BridgeResponseURL", "")

for _, test := range cases {
t.Run(test.name, func(t *testing.T) {
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestBridge_Perform_startANewRun(t *testing.T) {

store, cleanup := cltest.NewStore()
defer cleanup()
store.Config.BridgeResponseURL = cltest.WebURL("")
store.Config.Set("BridgeResponseURL", "")
runID := utils.NewBytes32ID()
wantedBody := fmt.Sprintf(`{"id":"%v","data":{"value":"lot 49"}}`, runID)

Expand Down Expand Up @@ -155,7 +155,7 @@ func TestBridge_Perform_responseURL(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
store, cleanup := cltest.NewStore()
defer cleanup()
store.Config.BridgeResponseURL = test.configuredURL
store.Config.Set("BridgeResponseURL", test.configuredURL)

mock, ensureCalled := cltest.NewHTTPMockServer(t, 200, "POST", ``,
func(_ http.Header, body string) {
Expand Down
12 changes: 6 additions & 6 deletions adapters/eth_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestEthTxAdapter_Perform_Confirmed(t *testing.T) {
hash := cltest.NewHash()
sentAt := uint64(23456)
confirmed := sentAt + 1
safe := confirmed + config.MinOutgoingConfirmations
safe := confirmed + config.MinOutgoingConfirmations()
ethMock.Register("eth_sendRawTransaction", hash,
func(_ interface{}, data ...interface{}) error {
rlp := data[0].([]interface{})[0].(string)
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestEthTxAdapter_Perform_ConfirmedWithBytes(t *testing.T) {
hash := cltest.NewHash()
sentAt := uint64(23456)
confirmed := sentAt + 1
safe := confirmed + config.MinOutgoingConfirmations
safe := confirmed + config.MinOutgoingConfirmations()
ethMock.Register("eth_sendRawTransaction", hash,
func(_ interface{}, data ...interface{}) error {
rlp := data[0].([]interface{})[0].(string)
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestEthTxAdapter_Perform_ConfirmedWithBytesAndNoDataPrefix(t *testing.T) {
hash := cltest.NewHash()
sentAt := uint64(23456)
confirmed := sentAt + 1
safe := confirmed + config.MinOutgoingConfirmations
safe := confirmed + config.MinOutgoingConfirmations()
ethMock.Register("eth_sendRawTransaction", hash,
func(_ interface{}, data ...interface{}) error {
rlp := data[0].([]interface{})[0].(string)
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestEthTxAdapter_Perform_FromPendingConfirmations_StillPending(t *testing.T
ethMock := app.MockEthClient()
ethMock.Register("eth_getTransactionReceipt", strpkg.TxReceipt{})
sentAt := uint64(23456)
ethMock.Register("eth_blockNumber", utils.Uint64ToHex(sentAt+config.EthGasBumpThreshold-1))
ethMock.Register("eth_blockNumber", utils.Uint64ToHex(sentAt+config.EthGasBumpThreshold()-1))

require.NoError(t, app.StartAndConnect())

Expand Down Expand Up @@ -257,7 +257,7 @@ func TestEthTxAdapter_Perform_FromPendingConfirmations_BumpGas(t *testing.T) {
sentAt := uint64(23456)
ethMock.Context("ethtx perform", func(ethMock *cltest.EthMock) {
ethMock.Register("eth_getTransactionReceipt", strpkg.TxReceipt{})
ethMock.Register("eth_blockNumber", utils.Uint64ToHex(sentAt+config.EthGasBumpThreshold))
ethMock.Register("eth_blockNumber", utils.Uint64ToHex(sentAt+config.EthGasBumpThreshold()))
ethMock.Register("eth_sendRawTransaction", cltest.NewHash())
})

Expand Down Expand Up @@ -297,7 +297,7 @@ func TestEthTxAdapter_Perform_FromPendingConfirmations_ConfirmCompletes(t *testi
Hash: cltest.NewHash(),
BlockNumber: cltest.Int(sentAt),
})
confirmedAt := sentAt + config.MinOutgoingConfirmations - 1 // confirmations are 0-based idx
confirmedAt := sentAt + config.MinOutgoingConfirmations() - 1 // confirmations are 0-based idx
ethMock.Register("eth_blockNumber", utils.Uint64ToHex(confirmedAt))

require.NoError(t, app.StartAndConnect())
Expand Down
2 changes: 1 addition & 1 deletion cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func NewApp(client *Client) *cli.App {
},
}

if client.Config.Dev {
if client.Config.Dev() {
createextrakey := cli.Command{
Name: "createextrakey",
Usage: "Create a key in the node's keystore alongside the existing key; to create an original key, just run the node",
Expand Down
Loading

0 comments on commit 75c0ec5

Please sign in to comment.