Skip to content

Commit

Permalink
fix shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitAD committed Sep 29, 2021
1 parent 6cc03a9 commit 4779275
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 4 additions & 3 deletions provider/bidengine/pricing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,17 +556,18 @@ func Test_ScriptPricingFromScript(t *testing.T) {
)

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, mockApiResponse)
_, err := fmt.Fprint(w, mockApiResponse)
require.NoError(t, err)
})

go func() {
t.Fatal(http.ListenAndServe(addr, nil))
t.Error(http.ListenAndServe(addr, nil))
}()

err := os.Setenv("API_URL", addr)
require.NoError(t, err)

scriptPath, err := filepath.Abs("testdata/usd_pricing_oracle.sh")
scriptPath, err := filepath.Abs("../../script/usd_pricing_oracle.sh")
require.NoError(t, err)
pricing, err := MakeShellScriptPricing(scriptPath, 1, 30000*time.Millisecond)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#!/bin/bash

#URL to get current USD price per AKT
# To run this script, the following commands need to be installed:
#
# * jq
# * bc
# * curl

# One can set API_URL env variable to the url that returns coingecko like response, something like: `{"akash-network":{"usd":3.57}}`
# and if the API_URL isn't set, the default api url will be used

# URL to get current USD price per AKT
DEFAULT_API_URL="https://api.coingecko.com/api/v3/simple/price?ids=akash-network&vs_currencies=usd"

# These are the variables one can modify to change the USD scale for each resource kind
Expand Down Expand Up @@ -67,15 +76,15 @@ if [ -z "$API_URL" ]; then
API_URL=$DEFAULT_API_URL
fi

API_RESPONSE=$(curl -s $API_URL)
API_RESPONSE=$(curl -s "$API_URL")
curl_exit_status=$?
if [ $curl_exit_status != 0 ]; then
exit $curl_exit_status
fi
usd_per_akt=$(jq '."akash-network"."usd"' <<<"$API_RESPONSE")

#validate the current USD price per AKT is not zero
if [ "$usd_per_akt" == 0 ]; then
# validate the current USD price per AKT is not zero
if [ 1 -eq "$(bc <<< "${usd_per_akt}==0")" ]; then
exit 1
fi

Expand All @@ -87,4 +96,4 @@ total_cost_uakt=$(bc -l <<<"${total_cost_akt}*1000000")
total_cost_uakt=$(echo "$total_cost_uakt" | jq '.|ceil')

# return the price in uAKT
echo "$total_cost_uakt"
echo "$total_cost_uakt"

0 comments on commit 4779275

Please sign in to comment.