Skip to content

Commit

Permalink
Gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznecovas committed May 14, 2020
1 parent cc4b2c9 commit d7d86ab
Show file tree
Hide file tree
Showing 16 changed files with 1,067 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
34 changes: 34 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
stages:
- test
- release

variables:
BUILD_COMMIT: $CI_COMMIT_SHORT_SHA
BUILD_BRANCH: $CI_COMMIT_REF_NAME
BUILD_BRANCH_SAFE: $CI_COMMIT_REF_SLUG
BUILD_TAG: $CI_COMMIT_TAG
BUILD_NUMBER: $CI_PIPELINE_ID
GITHUB_OWNER: mysteriumnetwork
GITHUB_REPO: payments-smart-contracts

GO_PACKAGE: github.com/mysteriumnetwork/payments-smart-contracts
GIT_CLONE_PATH: /home/gitlab-runner/go/src/$GO_PACKAGE
GOFLAGS: "-count=1" # Supersedes GOCACHE=off, see: https://github.com/golang/go/issues/29378#issuecomment-449383809

after_script:
# docker based jobs leave files owned by root
- sudo chown -R gitlab-runner:gitlab-runner $GOPATH

e2e:
stage: test
tags: [go]
script: go run mage.go -v e2e

artifacts:
only:
- tags
stage: release
tags: [go]
script: go run mage.go -v release


8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:12.16.3

WORKDIR /src
ADD . /src

RUN npm i
RUN npm run compile

12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ We're using truffle for smart contract compilation and running tests.
npm install
```

2. Run local ethereum node, e.g. `ganache`.
2. Run local ethereum node, e.g. `ganache`. Make sure to use version greater than 6.9.1.

```bash
npx ganache-cli --port 7545 --mnemonic "amused glory pen avocado toilet dragon entry kitchen cliff retreat canyon danger"
Expand All @@ -36,6 +36,16 @@ npm test
npm run migrate
```

**NOTE** IF your tests fail, first thing to check is the config address in `accountantImplementationProxy.sol` and `channelImplementationProxy.sol`.

When running tests, you'll see a line in stdout, with a config address like so:

`Config address: 0xed3585D6BEEE0f045E209dbc419C2ad0c3138612`

Change the CONFIG_ADDRESS constants to point to the address that your terminal displays and tests should work.

`address constant CONFIG_ADDRESS = 0xed3585D6BEEE0f045E209dbc419C2ad0c3138612;`

## Current deployment (ethereum Görli testnet)
MYSTT ERC20 Token (Mintable a la myst token): [0x7753cfAD258eFbC52A9A1452e42fFbce9bE486cb](https://goerli.etherscan.io/address/0x7753cfAD258eFbC52A9A1452e42fFbce9bE486cb)

Expand Down
25 changes: 25 additions & 0 deletions ci/e2e.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ci

import (
"strings"

"github.com/magefile/mage/sh"
"github.com/rs/zerolog/log"
)

// E2e runs the e2e test suite.
func E2e() error {
defer sh.RunV("docker-compose", "down")
err := sh.RunV("docker-compose", "up", "--build", "-d")
if err != nil {
log.Info().Msg("Could not start containers")
return err
}
err = sh.RunV("docker", strings.Split("run --network payments-smart-contracts_default payments-smart-contracts_psc npm run e2e", " ")...)
if err != nil {
log.Info().Msg("Tests failed.")
return err
}
log.Info().Msg("Tests succeeded!")
return nil
}
55 changes: 55 additions & 0 deletions ci/release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ci

import (
"errors"
"fmt"
"os"
"strings"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/rs/zerolog/log"
)

func installGhrIfNeeded() error {
err := sh.Run("command", "-v", "ghr")
if err == nil {
return nil
}
log.Info().Msg("ghr not found, will install")
// Ideally, I'd just use a library, but all of them seem to live in the main package, so no import :(
return sh.RunV("go", "get", "-u", "github.com/tcnksm/ghr")
}

// Release releases the artifacts
func Release() error {
mg.Deps(installGhrIfNeeded)

tag := os.Getenv("BUILD_TAG")
if tag == "" {
return errors.New("no tag specified")
}
log.Info().Msgf("releasing for TAG: %v", tag)

defer sh.RunV("docker-compose", "down")
err := sh.RunV("docker-compose", "build", "psc")
if err != nil {
log.Error().Err(err).Msgf("could not build container")
return err
}

_ = os.Mkdir("./build", os.ModeDir)
o, err := sh.Output("docker", strings.Split("ps -a --filter ancestor=payments-smart-contracts_psc --format {{.ID}}", " ")...)
if err != nil {
log.Error().Err(err).Msgf("could not get container ID")
return err
}

err = sh.RunV("docker", fmt.Sprintf("cp %v:/src/build/ ./build", strings.TrimSpace(o)))
if err != nil {
log.Error().Err(err).Msgf("could not copy build artifacts")
return err
}

return sh.RunV("ghr", "-replace", tag, "build/contracts/")
}
2 changes: 1 addition & 1 deletion contracts/AccountantImplementationProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.5.12 <0.6.0;
import "./Config.sol";

contract AccountantImplementationProxy {
address constant CONFIG_ADDRESS = 0x46e9742C098267122DA466d6b7a3fb844436Ac37;
address constant CONFIG_ADDRESS = 0x0a0aA1711dF0A972655914244507D0f6fa852B6F;

function () external payable {
address _target = Config(CONFIG_ADDRESS).getAddress(0xe6906d4b6048dd18329c27945d05f766dd19b003dc60f82fd4037c490ee55be0);
Expand Down
2 changes: 1 addition & 1 deletion contracts/ChannelIImplementationProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.5.12 <0.6.0;
import "./Config.sol";

contract ChannelImplementationProxy {
address constant CONFIG_ADDRESS = 0x46e9742C098267122DA466d6b7a3fb844436Ac37;
address constant CONFIG_ADDRESS = 0x0a0aA1711dF0A972655914244507D0f6fa852B6F;

function () external payable {
address _target = Config(CONFIG_ADDRESS).getAddress(0x48df65c92c1c0e8e19a219c69bfeb4cf7c1c123e0c266d555abb508d37c6d96e); // keccak256('channel implementation')
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.0'
services:
psc:
build:
context: .
dockerfile: ./Dockerfile
depends_on:
- ganache
ganache:
image: trufflesuite/ganache-cli:v6.9.1
expose:
- 8545
command: >
--mnemonic "amused glory pen avocado toilet dragon entry kitchen cliff retreat canyon danger"
20 changes: 20 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/mysteriumnetwork/payments-smart-contracts

go 1.13

require (
github.com/ethereum/go-ethereum v1.9.14
github.com/golang/protobuf v1.4.1 // indirect
github.com/magefile/mage v1.9.0
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mysteriumnetwork/go-ci v0.0.0-20200415074834-39fc864b0ed4
github.com/mysteriumnetwork/node v0.0.0-20200514095209-be1b164ff528 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rs/zerolog v1.17.2
github.com/tcnksm/ghr v0.13.0 // indirect
golang.org/x/net v0.0.0-20200513185701-a91f0712d120 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
golang.org/x/sys v0.0.0-20200513112337-417ce2331b5c // indirect
google.golang.org/appengine v1.6.6 // indirect
)
Loading

0 comments on commit d7d86ab

Please sign in to comment.