Skip to content

Commit 0bb4e93

Browse files
authored
Integration CI on this repo (#112)
Adds smoke tests to the framework repo's CI
1 parent f82a658 commit 0bb4e93

19 files changed

+287
-65
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: golangci-lint
1+
name: Linting
22
on:
33
push:
44
tags:

.github/workflows/test.yaml

Lines changed: 164 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: test
1+
name: Tests
22
on:
33
push:
44
tags:
@@ -8,7 +8,7 @@ on:
88
- main
99
pull_request:
1010
jobs:
11-
test:
11+
unit:
1212
strategy:
1313
matrix:
1414
go-version: [1.16.x]
@@ -24,26 +24,175 @@ jobs:
2424
--health-timeout 5s
2525
--health-retries 5
2626
steps:
27-
- name: Install Go
27+
- name: Checkout the Repo
28+
uses: actions/checkout@v2
29+
- name: Setup Go
2830
uses: actions/setup-go@v2
2931
with:
3032
go-version: ${{ matrix.go-version }}
31-
- name: Checkout code
32-
uses: actions/checkout@v2
33-
- name: Test
34-
run: go test ./client ./config ./environment -v -covermode=count -coverprofile=coverage.out
35-
- name: Convert coverage to lcov
36-
uses: jandelgado/[email protected]
33+
- name: Configure AWS Credentials
34+
uses: aws-actions/configure-aws-credentials@v1
35+
with:
36+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
37+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
38+
aws-region: ${{ secrets.AWS_REGION }}
39+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
40+
role-duration-seconds: 3600
41+
- name: Set Kubernetes Context
42+
uses: azure/k8s-set-context@v1
43+
with:
44+
method: kubeconfig
45+
kubeconfig: ${{ secrets.KUBECONFIG }}
46+
- name: Cache Vendor Packages
47+
uses: actions/cache@v2
48+
id: cache-packages
49+
with:
50+
path: |
51+
~/.cache/go-build
52+
~/go/pkg/mod
53+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
54+
restore-keys: |
55+
${{ runner.os }}-go-
56+
- name: Download Go Vendor Packages
57+
if: steps.cache-packages.outputs.cache-hit != 'true'
58+
run: go mod download
59+
- name: Install Ginkgo CLI
60+
run: go install github.com/onsi/ginkgo/ginkgo
61+
- name: Run Tests
62+
run: |
63+
export PATH=$PATH:$(go env GOPATH)/bin
64+
ginkgo -r --randomizeAllSpecs --randomizeSuites -keepGoing -covermode=count -coverprofile=unit-test-coverage.out -nodes=10 ./client ./config ./environment
65+
- name: Code Coverage
66+
uses: codecov/codecov-action@v2
67+
with:
68+
files: ./unit-test-coverage.out
69+
name: codecov-umbrella
70+
- name: Publish Unit Test Results
71+
uses: mikepenz/action-junit-report@v2
3772
if: always()
38-
- name: Report code coverage
39-
uses: romeovs/[email protected]
73+
with:
74+
report_paths: '**/logs/tests-*.xml'
75+
github_token: ${{ secrets.GITHUB_TOKEN }}
76+
- name: Publish Artifacts
77+
if: failure()
78+
uses: actions/upload-artifact@v1
79+
with:
80+
name: test-logs
81+
path: ./logs
82+
83+
smoke:
84+
runs-on: ubuntu-latest
85+
needs: unit
86+
env:
87+
CGO_ENABLED: 0
88+
steps:
89+
- name: Checkout the repo
90+
uses: actions/checkout@v2
91+
- name: Setup go
92+
uses: actions/setup-go@v1
93+
with:
94+
go-version: 1.16
95+
- name: Configure AWS Credentials
96+
uses: aws-actions/configure-aws-credentials@v1
97+
with:
98+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
99+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
100+
aws-region: ${{ secrets.AWS_REGION }}
101+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
102+
role-duration-seconds: 3600
103+
- name: Set Kubernetes Context
104+
uses: azure/k8s-set-context@v1
105+
with:
106+
method: kubeconfig
107+
kubeconfig: ${{ secrets.KUBECONFIG }}
108+
- name: Cache Vendor Packages
109+
uses: actions/cache@v2
110+
id: cache-packages
111+
with:
112+
path: |
113+
~/.cache/go-build
114+
~/go/pkg/mod
115+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
116+
restore-keys: |
117+
${{ runner.os }}-go-
118+
- name: Download Go Vendor Packages
119+
if: steps.cache-packages.outputs.cache-hit != 'true'
120+
run: go mod download
121+
- name: Install Ginkgo CLI
122+
run: go install github.com/onsi/ginkgo/ginkgo
123+
- name: Run Tests
124+
run: |
125+
export PATH=$PATH:$(go env GOPATH)/bin
126+
./tools/integration_test.sh 0
127+
- name: Publish Test Results
128+
uses: mikepenz/action-junit-report@v2
40129
if: always()
41130
with:
42-
github-token: ${{ secrets.GITHUB_TOKEN }}
43-
lcov-file: ./coverage.lcov
44-
- name: Publish Unit Test Results
131+
report_paths: '**/logs/tests-*.xml'
132+
github_token: ${{ secrets.GITHUB_TOKEN }}
133+
- name: Publish Artifacts
134+
if: failure()
135+
uses: actions/upload-artifact@v1
136+
with:
137+
name: test-logs
138+
path: ./logs
139+
140+
performance:
141+
# Only run performance tests on significant PRs / merges to main
142+
if: startsWith(github.ref, 'v') || contains(github.ref, 'main') || contains(github.ref, 'develop')
143+
needs: unit
144+
runs-on: ubuntu-latest
145+
env:
146+
CGO_ENABLED: 0
147+
NETWORK: ethereum_geth_performance
148+
steps:
149+
- name: Checkout the repo
150+
uses: actions/checkout@v2
151+
- name: Setup Go
152+
uses: actions/setup-go@v1
153+
with:
154+
go-version: 1.16
155+
- name: Configure AWS Credentials
156+
uses: aws-actions/configure-aws-credentials@v1
157+
with:
158+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
159+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
160+
aws-region: ${{ secrets.AWS_REGION }}
161+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
162+
role-duration-seconds: 3600
163+
- name: Set Kubernetes Context
164+
uses: azure/k8s-set-context@v1
165+
with:
166+
method: kubeconfig
167+
kubeconfig: ${{ secrets.KUBECONFIG }}
168+
- name: Cache Vendor Packages
169+
uses: actions/cache@v2
170+
id: cache-packages
171+
with:
172+
path: |
173+
~/.cache/go-build
174+
~/go/pkg/mod
175+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
176+
restore-keys: |
177+
${{ runner.os }}-go-
178+
- name: Download Go Vendor Packages
179+
if: steps.cache-packages.outputs.cache-hit != 'true'
180+
run: go mod download
181+
- name: Install Ginkgo CLI
182+
run: go install github.com/onsi/ginkgo/ginkgo
183+
- name: Run Tests
184+
run: |
185+
export PATH=$PATH:$(go env GOPATH)/bin
186+
./tools/integration_test.sh 1
187+
- name: Publish Test Results
45188
uses: mikepenz/action-junit-report@v2
46189
if: always()
47190
with:
48-
report_paths: '**/junit.xml'
191+
report_paths: '**/logs/tests-*.xml'
49192
github_token: ${{ secrets.GITHUB_TOKEN }}
193+
- name: Publish Artifacts
194+
if: failure()
195+
uses: actions/upload-artifact@v1
196+
with:
197+
name: test-logs
198+
path: ./logs

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ This framework is still very much a work in progress, and will have frequent cha
1313
breaking.
1414

1515
### Setup
16+
1617
Install CLI
17-
```
18+
19+
```sh
1820
make install_cli
1921
```
2022

@@ -24,20 +26,23 @@ A simple example on deploying and interaction with a simple contract using this
2426

2527
```go
2628
var _ = Describe("Basic Contract Interactions", func() {
27-
var suiteSetup *actions.DefaultSuiteSetup
28-
var defaultWallet client.BlockchainWallet
29+
var (
30+
suiteSetup actions.SuiteSetup
31+
networkInfo actions.NetworkInfo
32+
defaultWallet client.BlockchainWallet
33+
)
2934

3035
BeforeEach(func() {
3136
By("Deploying the environment", func() {
32-
confFileLocation, err := filepath.Abs("../") // Get the absolute path of the test suite's root directory
33-
Expect(err).ShouldNot(HaveOccurred())
34-
suiteSetup, err = actions.DefaultLocalSetup(
37+
var err error
38+
suiteSetup, err = actions.SingleNetworkSetup(
3539
environment.NewChainlinkCluster(0),
36-
client.NewNetworkFromConfig,
37-
confFileLocation, // Directory where config.yml is placed
40+
client.DefaultNetworkFromConfig,
41+
tools.ProjectRoot,
3842
)
3943
Expect(err).ShouldNot(HaveOccurred())
40-
defaultWallet = suiteSetup.Wallets.Default()
44+
networkInfo = suiteSetup.DefaultNetwork()
45+
defaultWallet = networkInfo.Wallets.Default()
4146
})
4247
})
4348

@@ -110,13 +115,17 @@ NETWORK="ethereum_geth_performance" make test_performance
110115
```
111116

112117
### Build contracts
118+
113119
Example of generating go bindings for Ethereum contracts
114-
```
120+
121+
```sh
115122
ifcli build_contracts -c config.yml
116123
```
117124

118125
### Create environment
126+
119127
Example of creating environment with one Chainlink node and Geth dev network
120-
```
128+
129+
```sh
121130
ifcli create_env -n ethereum_geth -t chainlink -c 1
122131
```

actions/actions.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package actions
22

33
import (
44
"encoding/json"
5+
"math/big"
6+
"strings"
7+
58
"github.com/ethereum/go-ethereum/common"
69
"github.com/pkg/errors"
7-
"github.com/satori/go.uuid"
10+
uuid "github.com/satori/go.uuid"
811
"github.com/smartcontractkit/integrations-framework/client"
9-
"math/big"
10-
"strings"
1112
)
1213

1314
// FundChainlinkNodes will fund all of the Chainlink nodes with a given amount of ETH in wei

client/blockchain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ func (e *EthereumNetwork) Wallets() (BlockchainWallets, error) {
223223

224224
// FluxMonitorSubmissionGasUsed Flux Monitor one submission gasUsed value
225225
func (e *EthereumNetwork) FluxMonitorSubmissionGasUsed() (*big.Int, error) {
226-
if e.networkConfig.Name == "Ethereum Geth dev" {
226+
if strings.HasPrefix(e.networkConfig.Name, "ethereum-geth") {
227227
return big.NewInt(400000), nil
228228
}
229-
return nil, errors.New("unknown gas used estimation")
229+
return nil, fmt.Errorf("gas used estimation unavailable for the network name '%s'", e.networkConfig.Name)
230230
}
231231

232232
// BlockchainWallets is an interface that when implemented is a representation of a slice of wallets for

client/client_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ import (
1414
func TestClient(t *testing.T) {
1515
RegisterFailHandler(Fail)
1616
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
17-
junitReporter := reporters.NewJUnitReporter("junit.xml")
17+
junitReporter := reporters.NewJUnitReporter("../logs/tests-client.xml")
1818
RunSpecsWithDefaultAndCustomReporters(t, "Client Suite", []Reporter{junitReporter})
1919
}

client/ethereum.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,18 @@ func (e *EthereumClient) Get() interface{} {
326326

327327
// CalculateTxGas calculates tx gas cost accordingly gas used plus buffer, converts it to big.Float for funding
328328
func (e *EthereumClient) CalculateTxGas(gasUsed *big.Int) (*big.Float, error) {
329-
gp, err := e.Client.SuggestGasPrice(context.Background())
329+
gasPrice, err := e.Client.SuggestGasPrice(context.Background()) // Wei
330330
if err != nil {
331331
return nil, err
332332
}
333-
gpWei := gp.Mul(gp, OneGWei)
334-
log.Debug().Int64("Gas price", gp.Int64()).Msg("Suggested gas price")
335-
buf := big.NewInt(int64(e.Network.Config().GasEstimationBuffer))
336-
gasUsedWithBuf := gasUsed.Add(gasUsed, buf)
337-
cost := big.NewInt(1).Mul(gpWei, gasUsedWithBuf)
338-
log.Debug().Int64("TX Gas cost", cost.Int64()).Msg("Estimated tx gas cost with buffer")
339-
bf := new(big.Float).SetInt(cost)
340-
return big.NewFloat(1).Quo(bf, OneEth), nil
333+
buffer := big.NewInt(0).SetUint64(e.Network.Config().GasEstimationBuffer)
334+
gasUsedWithBuffer := gasUsed.Add(gasUsed, buffer)
335+
cost := big.NewFloat(0).SetInt(big.NewInt(1).Mul(gasPrice, gasUsedWithBuffer))
336+
costInEth := big.NewFloat(0).Quo(cost, OneEth)
337+
costInEthFloat, _ := costInEth.Float64()
338+
339+
log.Debug().Float64("ETH", costInEthFloat).Msg("Estimated tx gas cost with buffer")
340+
return costInEth, nil
341341
}
342342

343343
// GasStats gets gas stats instance
@@ -366,7 +366,7 @@ func (e *EthereumClient) Fund(
366366
Str("Token", "ETH").
367367
Str("From", fromWallet.Address()).
368368
Str("To", toAddress).
369-
Str("Amount", eth.String()).
369+
Str("Amount", ethAmount.String()).
370370
Msg("Funding Address")
371371
_, err := e.SendTransaction(fromWallet, ethAddress, eth, nil)
372372
if err != nil {
@@ -381,7 +381,7 @@ func (e *EthereumClient) Fund(
381381
Str("Token", "LINK").
382382
Str("From", fromWallet.Address()).
383383
Str("To", toAddress).
384-
Str("Amount", link.String()).
384+
Str("Amount", linkAmount.String()).
385385
Msg("Funding Address")
386386
linkAddress := common.HexToAddress(e.Network.Config().LinkTokenAddress)
387387
linkInstance, err := ethContracts.NewLinkToken(linkAddress, e.Client)

config/config_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ import (
1414
func TestConfig(t *testing.T) {
1515
RegisterFailHandler(Fail)
1616
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
17-
junitReporter := reporters.NewJUnitReporter("junit.xml")
17+
junitReporter := reporters.NewJUnitReporter("../logs/tests-config.xml")
1818
RunSpecsWithDefaultAndCustomReporters(t, "Config Suite", []Reporter{junitReporter})
1919
}

environment/environment_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ var _ = Describe("Environment unit tests @unit", func() {
5454

5555
It("should fetch secret private keys", func() {
5656
Skip("Not ready to be run in github")
57-
5857
conf, err := config.NewConfig(fmt.Sprintf(secretKeysConfig, tools.ProjectRoot))
5958
Expect(err).ShouldNot(HaveOccurred())
6059

environment/k8s_environment.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (env *K8sEnvironment) deploySpecs(startIndex int, errChan chan<- error) {
405405
}
406406

407407
func (env *K8sEnvironment) createNamespace(namespace string) (*coreV1.Namespace, error) {
408-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
408+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
409409
defer cancel()
410410

411411
createdNamespace, err := env.k8sClient.CoreV1().Namespaces().Create(
@@ -417,9 +417,6 @@ func (env *K8sEnvironment) createNamespace(namespace string) (*coreV1.Namespace,
417417
},
418418
metaV1.CreateOptions{},
419419
)
420-
if err == nil {
421-
log.Info().Str("Namespace", createdNamespace.Name).Msg("Created namespace")
422-
}
423420
return createdNamespace, err
424421
}
425422

0 commit comments

Comments
 (0)