Skip to content

Commit

Permalink
Integration CI on this repo (#112)
Browse files Browse the repository at this point in the history
Adds smoke tests to the framework repo's CI
  • Loading branch information
kalverra authored Oct 20, 2021
1 parent f82a658 commit 0bb4e93
Show file tree
Hide file tree
Showing 19 changed files with 287 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: golangci-lint
name: Linting
on:
push:
tags:
Expand Down
179 changes: 164 additions & 15 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test
name: Tests
on:
push:
tags:
Expand All @@ -8,7 +8,7 @@ on:
- main
pull_request:
jobs:
test:
unit:
strategy:
matrix:
go-version: [1.16.x]
Expand All @@ -24,26 +24,175 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- name: Install Go
- name: Checkout the Repo
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: go test ./client ./config ./environment -v -covermode=count -coverprofile=coverage.out
- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1.0.5
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 3600
- name: Set Kubernetes Context
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}
- name: Cache Vendor Packages
uses: actions/cache@v2
id: cache-packages
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download Go Vendor Packages
if: steps.cache-packages.outputs.cache-hit != 'true'
run: go mod download
- name: Install Ginkgo CLI
run: go install github.com/onsi/ginkgo/ginkgo
- name: Run Tests
run: |
export PATH=$PATH:$(go env GOPATH)/bin
ginkgo -r --randomizeAllSpecs --randomizeSuites -keepGoing -covermode=count -coverprofile=unit-test-coverage.out -nodes=10 ./client ./config ./environment
- name: Code Coverage
uses: codecov/codecov-action@v2
with:
files: ./unit-test-coverage.out
name: codecov-umbrella
- name: Publish Unit Test Results
uses: mikepenz/action-junit-report@v2
if: always()
- name: Report code coverage
uses: romeovs/lcov-reporter-action@v0.2.21
with:
report_paths: '**/logs/tests-*.xml'
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Artifacts
if: failure()
uses: actions/upload-artifact@v1
with:
name: test-logs
path: ./logs

smoke:
runs-on: ubuntu-latest
needs: unit
env:
CGO_ENABLED: 0
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v1
with:
go-version: 1.16
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 3600
- name: Set Kubernetes Context
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}
- name: Cache Vendor Packages
uses: actions/cache@v2
id: cache-packages
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download Go Vendor Packages
if: steps.cache-packages.outputs.cache-hit != 'true'
run: go mod download
- name: Install Ginkgo CLI
run: go install github.com/onsi/ginkgo/ginkgo
- name: Run Tests
run: |
export PATH=$PATH:$(go env GOPATH)/bin
./tools/integration_test.sh 0
- name: Publish Test Results
uses: mikepenz/action-junit-report@v2
if: always()
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: ./coverage.lcov
- name: Publish Unit Test Results
report_paths: '**/logs/tests-*.xml'
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Artifacts
if: failure()
uses: actions/upload-artifact@v1
with:
name: test-logs
path: ./logs

performance:
# Only run performance tests on significant PRs / merges to main
if: startsWith(github.ref, 'v') || contains(github.ref, 'main') || contains(github.ref, 'develop')
needs: unit
runs-on: ubuntu-latest
env:
CGO_ENABLED: 0
NETWORK: ethereum_geth_performance
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.16
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 3600
- name: Set Kubernetes Context
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}
- name: Cache Vendor Packages
uses: actions/cache@v2
id: cache-packages
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download Go Vendor Packages
if: steps.cache-packages.outputs.cache-hit != 'true'
run: go mod download
- name: Install Ginkgo CLI
run: go install github.com/onsi/ginkgo/ginkgo
- name: Run Tests
run: |
export PATH=$PATH:$(go env GOPATH)/bin
./tools/integration_test.sh 1
- name: Publish Test Results
uses: mikepenz/action-junit-report@v2
if: always()
with:
report_paths: '**/junit.xml'
report_paths: '**/logs/tests-*.xml'
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Artifacts
if: failure()
uses: actions/upload-artifact@v1
with:
name: test-logs
path: ./logs
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ This framework is still very much a work in progress, and will have frequent cha
breaking.

### Setup

Install CLI
```

```sh
make install_cli
```

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

```go
var _ = Describe("Basic Contract Interactions", func() {
var suiteSetup *actions.DefaultSuiteSetup
var defaultWallet client.BlockchainWallet
var (
suiteSetup actions.SuiteSetup
networkInfo actions.NetworkInfo
defaultWallet client.BlockchainWallet
)

BeforeEach(func() {
By("Deploying the environment", func() {
confFileLocation, err := filepath.Abs("../") // Get the absolute path of the test suite's root directory
Expect(err).ShouldNot(HaveOccurred())
suiteSetup, err = actions.DefaultLocalSetup(
var err error
suiteSetup, err = actions.SingleNetworkSetup(
environment.NewChainlinkCluster(0),
client.NewNetworkFromConfig,
confFileLocation, // Directory where config.yml is placed
client.DefaultNetworkFromConfig,
tools.ProjectRoot,
)
Expect(err).ShouldNot(HaveOccurred())
defaultWallet = suiteSetup.Wallets.Default()
networkInfo = suiteSetup.DefaultNetwork()
defaultWallet = networkInfo.Wallets.Default()
})
})

Expand Down Expand Up @@ -110,13 +115,17 @@ NETWORK="ethereum_geth_performance" make test_performance
```

### Build contracts

Example of generating go bindings for Ethereum contracts
```

```sh
ifcli build_contracts -c config.yml
```

### Create environment

Example of creating environment with one Chainlink node and Geth dev network
```

```sh
ifcli create_env -n ethereum_geth -t chainlink -c 1
```
7 changes: 4 additions & 3 deletions actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package actions

import (
"encoding/json"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/satori/go.uuid"
uuid "github.com/satori/go.uuid"
"github.com/smartcontractkit/integrations-framework/client"
"math/big"
"strings"
)

// FundChainlinkNodes will fund all of the Chainlink nodes with a given amount of ETH in wei
Expand Down
4 changes: 2 additions & 2 deletions client/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ func (e *EthereumNetwork) Wallets() (BlockchainWallets, error) {

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

// BlockchainWallets is an interface that when implemented is a representation of a slice of wallets for
Expand Down
2 changes: 1 addition & 1 deletion client/client_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ import (
func TestClient(t *testing.T) {
RegisterFailHandler(Fail)
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
junitReporter := reporters.NewJUnitReporter("junit.xml")
junitReporter := reporters.NewJUnitReporter("../logs/tests-client.xml")
RunSpecsWithDefaultAndCustomReporters(t, "Client Suite", []Reporter{junitReporter})
}
22 changes: 11 additions & 11 deletions client/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,18 @@ func (e *EthereumClient) Get() interface{} {

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

log.Debug().Float64("ETH", costInEthFloat).Msg("Estimated tx gas cost with buffer")
return costInEth, nil
}

// GasStats gets gas stats instance
Expand Down Expand Up @@ -366,7 +366,7 @@ func (e *EthereumClient) Fund(
Str("Token", "ETH").
Str("From", fromWallet.Address()).
Str("To", toAddress).
Str("Amount", eth.String()).
Str("Amount", ethAmount.String()).
Msg("Funding Address")
_, err := e.SendTransaction(fromWallet, ethAddress, eth, nil)
if err != nil {
Expand All @@ -381,7 +381,7 @@ func (e *EthereumClient) Fund(
Str("Token", "LINK").
Str("From", fromWallet.Address()).
Str("To", toAddress).
Str("Amount", link.String()).
Str("Amount", linkAmount.String()).
Msg("Funding Address")
linkAddress := common.HexToAddress(e.Network.Config().LinkTokenAddress)
linkInstance, err := ethContracts.NewLinkToken(linkAddress, e.Client)
Expand Down
2 changes: 1 addition & 1 deletion config/config_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ import (
func TestConfig(t *testing.T) {
RegisterFailHandler(Fail)
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
junitReporter := reporters.NewJUnitReporter("junit.xml")
junitReporter := reporters.NewJUnitReporter("../logs/tests-config.xml")
RunSpecsWithDefaultAndCustomReporters(t, "Config Suite", []Reporter{junitReporter})
}
1 change: 0 additions & 1 deletion environment/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var _ = Describe("Environment unit tests @unit", func() {

It("should fetch secret private keys", func() {
Skip("Not ready to be run in github")

conf, err := config.NewConfig(fmt.Sprintf(secretKeysConfig, tools.ProjectRoot))
Expect(err).ShouldNot(HaveOccurred())

Expand Down
5 changes: 1 addition & 4 deletions environment/k8s_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (env *K8sEnvironment) deploySpecs(startIndex int, errChan chan<- error) {
}

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

createdNamespace, err := env.k8sClient.CoreV1().Namespaces().Create(
Expand All @@ -417,9 +417,6 @@ func (env *K8sEnvironment) createNamespace(namespace string) (*coreV1.Namespace,
},
metaV1.CreateOptions{},
)
if err == nil {
log.Info().Str("Namespace", createdNamespace.Name).Msg("Created namespace")
}
return createdNamespace, err
}

Expand Down
Loading

0 comments on commit 0bb4e93

Please sign in to comment.