Skip to content

Commit

Permalink
test: input etherscan API key through env
Browse files Browse the repository at this point in the history
  • Loading branch information
nanmu42 committed Feb 21, 2020
1 parent 84c69b5 commit 42ada40
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion setup_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@
package etherscan

import (
"fmt"
"os"
"testing"
"time"
)

const apiKeyEnvName = "ETHERSCAN_API_KEY"

var (
// api test client for many test cases
api *Client
// bucket default rate limiter
bucket *Bucket
// apiKey etherscan API key
apiKey string
)

func init() {
apiKey = os.Getenv(apiKeyEnvName)
if apiKey == "" {
panic(fmt.Sprintf("API key is empty, set env variable %q with a valid API key to proceed.", apiKeyEnvName))
}
bucket = NewBucket(200 * time.Millisecond)

api = New(Mainnet, "etherscan-api-e2e-test")
api = New(Mainnet, apiKey)
api.Verbose = true
api.BeforeRequest = func(module string, action string, param map[string]interface{}) error {
bucket.Take()
Expand Down

0 comments on commit 42ada40

Please sign in to comment.