Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/GBI-2105 - LP Swap local env scripts #532

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docker-compose/flyover-ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:18.20.3@sha256:70ae166dcb03837ebe1abbb78919a1a4bdc79cc970344d56f33b6c753f4b46cc AS builder

WORKDIR /code/flyover-ui
rafaiovlabs marked this conversation as resolved.
Show resolved Hide resolved

ARG VERSION="custom-lbc"
ARG LBC_ADDRESS


RUN --mount=type=secret,id=gh_token,required=true,uid=1000 gitrev="${VERSION}" && REPO_URL="https://$(cat /run/secrets/gh_token)@github.com/rsksmart/flyover-ui.git" &&\
git init && \
git remote add origin "$REPO_URL" && \
git fetch --depth 1 origin tag "$gitrev" && \
git checkout "$gitrev"

RUN --mount=type=secret,id=gh_token,required=true,uid=1000 npm config set //npm.pkg.github.com/:_authToken $(cat /run/secrets/gh_token)
RUN npm ci

RUN echo "REACT_APP_ENV=Regtest" > .env
RUN echo "REACT_APP_RPC_URL=http://localhost:4444" >> .env
RUN echo "REACT_APP_CUSTOM_LBC=$LBC_ADDRESS" >> .env


RUN npm run build


FROM nginx:1.27.1@sha256:135fbc7ed19c8f644ddf678e68292e678696908451dad7ee2fd4e0cf861f4b6f
COPY --from=builder /code/flyover-ui/build /usr/share/nginx/html

EXPOSE 80

STOPSIGNAL SIGTERM

CMD ["nginx", "-g", "daemon off;"]
7 changes: 4 additions & 3 deletions sample-config.env
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ PROVIDER_TYPE=both
PEGOUT_DEPOSIT_CACHE_START_BLOCK=0

# Captcha env
CAPTCHA_SECRET_KEY=
CAPTCHA_SITE_KEY=
# Suggestion: use public test keys -> https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do
CAPTCHA_SECRET_KEY=some-key
CAPTCHA_SITE_KEY=some-key
CAPTCHA_THRESHOLD=0.8
DISABLE_CAPTCHA=true
CAPTCHA_URL="https://www.google.com/recaptcha/api/siteverify"
Expand All @@ -67,4 +68,4 @@ AWS_REGION=us-east-1

# Used by local scripts
LIQUIDITY_PROVIDER_RSK_ADDR=0x9D93929A9099be4355fC2389FbF253982F9dF47c
GITHUB_TOKEN=
GITHUB_TOKEN=
4 changes: 2 additions & 2 deletions test/integration/integration-test.config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"rpcEndpoint": "localhost:5555",
"user": "test",
"password": "test",
"password": "test-password"
"walletPassword": "test-password"
},
"rsk": {
"rpcUrl": "ws://localhost:4445/websocket",
"lbcAddress": "<lbc address>",
"userPrivateKey": "<user private key>"
}
}
}
55 changes: 1 addition & 54 deletions test/integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/rsksmart/liquidity-provider-server/cmd/application/lps"
"github.com/rsksmart/liquidity-provider-server/internal/adapters/dataproviders/rootstock/bindings"
"github.com/rsksmart/liquidity-provider-server/pkg"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"io"
"net/http"
"os"
"testing"
"time"
Expand Down Expand Up @@ -55,7 +53,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
var configFile *os.File

log.Debug("Setting up integration tests...")
if configFile, err = os.Open("test/integration/integration-test.config.json"); err != nil {
if configFile, err = os.Open("./integration-test.config.json"); err != nil {
s.FailNow("Error reading configuration file", err)
}
defer func(configFile *os.File) {
Expand Down Expand Up @@ -85,13 +83,6 @@ func (s *IntegrationTestSuite) SetupSuite() {
time.Sleep(3 * time.Second)
}

if s.config.Network == "regtest" {
log.Warn("Setting limits for regtest operations. This requires the management API enabled.")
if err = s.configureRegtestLimits(); err != nil {
s.FailNow("Error setting regtest limits", err)
}
}

log.Debug("Set up completed")
}

Expand Down Expand Up @@ -155,50 +146,6 @@ func (s *IntegrationTestSuite) setupRsk() error {
return nil
}

func (s *IntegrationTestSuite) configureRegtestLimits() error {
url := s.config.Lps.Url
result, err := execute[any](Execution{
Method: http.MethodPost,
URL: url + "/pegin/configuration",
Body: pkg.PeginConfigurationRequest{
Configuration: pkg.PeginConfigurationDTO{
TimeForDeposit: 3600,
CallTime: 7200,
PenaltyFee: "1000000000000000",
CallFee: "10000000000000000",
MaxValue: "10000000000000000000",
MinValue: "600000000000000000",
},
},
})
if err != nil {
return err
} else if result.StatusCode != 204 {
return fmt.Errorf("unexpected status code: %v", result.StatusCode)
}
result, err = execute[any](Execution{
Method: http.MethodPost,
URL: url + "/pegout/configuration",
Body: pkg.PegoutConfigurationRequest{
Configuration: pkg.PegoutConfigurationDTO{
TimeForDeposit: 3600,
ExpireTime: 7200,
PenaltyFee: "1000000000000000",
CallFee: "10000000000000000",
MaxValue: "10000000000000000000",
MinValue: "600000000000000000",
ExpireBlocks: 500,
},
},
})
if err != nil {
return err
} else if result.StatusCode != 204 {
return fmt.Errorf("unexpected status code: %v", result.StatusCode)
}
return nil
}

func (s *IntegrationTestSuite) AssertFields(expectedFields []string, object map[string]any) {
for _, field := range expectedFields {
_, exists := object[field]
Expand Down
3 changes: 2 additions & 1 deletion test/integration/pegin_overpay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/big"
"os"
"os/signal"
"strings"
"syscall"
)

Expand Down Expand Up @@ -51,7 +52,7 @@ func (s *IntegrationTestSuite) TestPegInOverPayFlow() {
case balanceIncreaseEvent := <-balanceIncreaseChannel:
balanceIncreaseSubscription.Unsubscribe()
refundedAmount := new(entities.Wei).Add(value, new(entities.Wei).Add(callFee, gasFee))
s.Require().Equal(quote.Quote.LPRSKAddr, balanceIncreaseEvent.Dest.String())
s.Require().Equal(strings.ToLower(quote.Quote.LPRSKAddr), strings.ToLower(balanceIncreaseEvent.Dest.String()))
s.Require().Equal(refundedAmount.AsBigInt().Int64(), balanceIncreaseEvent.Amount.Int64())
registered = true
case err = <-balanceIncreaseSubscription.Err():
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pegout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *IntegrationTestSuite) TestSuccessfulPegOutFlow() {
txHash := waitForBtcTransactionToAddress(s, address)

txParsedHash, _ := chainhash.NewHashFromStr(txHash)
tx, err := s.btc.GetTransaction(txParsedHash)
tx, err := s.btc.GetRawTransaction(txParsedHash)
s.NoError(err)
s.NotNil(tx)
})
Expand Down
5 changes: 5 additions & 0 deletions test/lp-swap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.env
*-key.json
config.json
cookie_jar.txt
gh_token.txt
29 changes: 29 additions & 0 deletions test/lp-swap/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Liquidity Provider Swap environment
This is a simple environment for simulating a liquidity provider swap.
This is the process where one provider is added to the Liquidity Bridge Contract to coexist with the existing provider for some time.
After that time, the old provider is removed and the new provider is the only one providing liquidity.
This environment can be used to perform all the required validations over this process.

## How to run
1. Complete the missing variables in [sample-config.env](../../sample-config.env) since this file will be used as a template for the LPs env files.
Most likely the changes that you will need to do are setting the captcha keys (you can use the test ones) and setting the GITHUB_TOKEN in case the
environment is using any internal version.
2. Create a `config.json` with the same structure as `config.example.json` in the lp-swap folder (the same one where this file is located).
3. Run the following command:
```bash
./setup.sh
```
This script will set up the whole environment for you and will stop when both LPs are running. The user will be able to use both providers until he decides
to sunset one of them, at that point he just need to specify the ID in the console (the script will be waiting for that ID). After that, the script will
proceed to resign the LP and withdraw its collateral from the contract.

### Miners
Most of the operations that the LP needs to perform require a miner to be running so the transactions can achieve certain number of confirmations.
There is one script for each network; [btc-miner.sh](btc-miner.sh) and [rsk-miner.sh](rsk-miner.sh). These scripts will start a miner for the specified local network.
They only require one argument which is the number of seconds between blocks. E.g.:
```bash
./btc-miner.sh 60
```

## Clarifications
- This environment doesn't include the powpeg nodes so the LPs won't be refunded for the peins or pegouts done in it.
33 changes: 33 additions & 0 deletions test/lp-swap/btc-miner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

if ! [[ "$1" =~ ^[0-9]+$ ]]; then
echo "Argument must be a number"
exit 1
fi

RPC_IP=127.0.0.1
RPC_USER="test"
RPC_PASSWORD="test"
RPC_PORT=5555

WALLETS=$(bitcoin-cli -rpcuser=$RPC_USER -rpcpassword=$RPC_PASSWORD -rpcport=$RPC_PORT -rpcconnect=$RPC_IP listwallets)
if ! [[ $WALLETS == *"main"* ]]; then
bitcoin-cli -rpcuser=$RPC_USER -rpcpassword=$RPC_PASSWORD -rpcport=$RPC_PORT -rpcconnect=$RPC_IP \
createwallet "main" false false "test-password" true false true
ADDRESS=$(bitcoin-cli -rpcuser=$RPC_USER -rpcpassword=$RPC_PASSWORD -rpcport=$RPC_PORT -rpcconnect=$RPC_IP \
-rpcwallet=main getnewaddress)
bitcoin-cli -rpcuser=$RPC_USER -rpcpassword=$RPC_PASSWORD -rpcport=$RPC_PORT -rpcconnect=$RPC_IP \
generatetoaddress 100 "$ADDRESS"
fi

while true; do
bitcoin-cli -rpcuser=$RPC_USER -rpcpassword=$RPC_PASSWORD -rpcport=$RPC_PORT -rpcconnect=$RPC_IP \
-rpcwallet=main walletpassphrase "test-password" "$1"
ADDRESS=$(bitcoin-cli -rpcuser=$RPC_USER -rpcpassword=$RPC_PASSWORD -rpcport=$RPC_PORT -rpcconnect=$RPC_IP \
-rpcwallet=main getnewaddress)
bitcoin-cli -rpcuser=$RPC_USER -rpcpassword=$RPC_PASSWORD -rpcport=$RPC_PORT -rpcconnect=$RPC_IP \
-rpcwallet=main -named sendtoaddress address="$ADDRESS" fee_rate=25 amount=0.00001
bitcoin-cli -rpcuser=$RPC_USER -rpcpassword=$RPC_PASSWORD -rpcport=$RPC_PORT -rpcconnect=$RPC_IP \
-rpcwallet=main -generate 1
sleep "$1"
done
11 changes: 11 additions & 0 deletions test/lp-swap/config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ghToken": "",
"lp1": {
"key": {"address":"b4cbc80da6586615da4ac51416e0fac15d435750","crypto":{"cipher":"aes-128-ctr","ciphertext":"666596e67e2d952bb4278245f3bf8b6259d1c591939625fb3d03109d7d5e3f22","cipherparams":{"iv":"7fbc0ffe4103b311826344d370ef3912"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"d87b8fd0c391533502644dda48f9ff059e1151e0c64f37954af20f7e17c6fbfa"},"mac":"fecef2821c7fea325d1050b35fedd7e15b7051baa95ab8f7aaf48eee43ae8b7d"},"id":"bec11a9d-db99-44cb-924a-5c3b61dd0334","version":3},
"password": "test"
},
"lp2": {
"key": {"address":"f6af42d4f3487799fc48537775b3908a89ca7cb3","crypto":{"cipher":"aes-128-ctr","ciphertext":"c23a4ec21133141202012075497e6e82c2241fa06cdff4da07eef64d0c668d17","cipherparams":{"iv":"b7671d8e8811ab8de6d9511301d412d9"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"f2291e0af522984420d04ad4a1d073333b87fca41159c21cd2cea588888101fe"},"mac":"205006c4cbd477e60d2b3a45735136c43c114ad84972eeae2a40d56f4bd856eb"},"id":"1f97470e-e352-4dd1-bbcb-120aca9321d0","version":3},
"password": "test"
}
}
94 changes: 94 additions & 0 deletions test/lp-swap/docker-compose.lps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
services:
lps:
build:
context: ../../
dockerfile: docker-compose/lps/Dockerfile
image: lps:latest
depends_on:
- mongodb
volumes:
- ./:/mnt
environment:
- LPS_STAGE
- SERVER_PORT
- LOG_LEVEL
- LOG_FILE
- ENABLE_MANAGEMENT_API
- MONGODB_USER
- MONGODB_PASSWORD
- MONGODB_HOST
- MONGODB_PORT
- RSK_ENDPOINT
- CHAIN_ID
- LBC_ADDR
- RSK_BRIDGE_ADDR
- RSK_REQUIRED_BRIDGE_CONFIRMATIONS
- IRIS_ACTIVATION_HEIGHT
- ERP_KEYS
- ACCOUNT_NUM
- DAO_FEE_COLLECTOR_ADDRESS
- KEY_SECRET
- PASSWORD_SECRET
- RSK_CONFIRMATIONS
- BTC_NETWORK
- BTC_USERNAME
- BTC_PASSWORD
- BTC_ENDPOINT
- BTC_CONFIRMATIONS
- ALERT_SENDER_EMAIL
- ALERT_RECIPIENT_EMAIL
- PROVIDER_NAME
- BASE_URL
- PROVIDER_TYPE
- PEGIN_TIME_FOR_DEPOSIT
- PEGIN_CALL_TIME
- PEGIN_PENALTY_FEE
- PEGIN_FEE
- PEGIN_MIN_TRANSACTION_VALUE
- PEGIN_MAX_TRANSACTION_VALUE
- PEGOUT_TIME_FOR_DEPOSIT
- PEGOUT_CALL_TIME
- PEGOUT_PENALTY_FEE
- PEGOUT_FEE
- PEGOUT_MIN_TRANSACTION_VALUE
- PEGOUT_MAX_TRANSACTION_VALUE
- PEGOUT_EXPIRE_BLOCKS
- PEGOUT_DEPOSIT_CACHE_START_BLOCK
- CAPTCHA_SECRET_KEY
- CAPTCHA_SITE_KEY
- CAPTCHA_THRESHOLD
- DISABLE_CAPTCHA
- CAPTCHA_URL
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_REGION
- AWS_LOCAL_ENDPOINT
- MANAGEMENT_AUTH_KEY
- MANAGEMENT_ENCRYPTION_KEY
- MANAGEMENT_TOKEN_AUTH_KEY
- MANAGEMENT_USE_HTTPS
- WALLET
- SECRET_SRC
- KEYSTORE_FILE
- KEYSTORE_PWD
ports:
- "8080-8081:8080"
networks:
- lp-swap-network
command: ["liquidity-provider-server"]
mongodb:
image: mongo:4
restart: on-failure
environment:
- MONGO_INITDB_ROOT_USERNAME=root
Luisfc68 marked this conversation as resolved.
Show resolved Hide resolved
- MONGO_INITDB_ROOT_PASSWORD=root
- MONGO_INITDB_DATABASE=flyover
ports:
- "27017-27018:27017"
expose:
- 27017
networks:
- lp-swap-network
networks:
lp-swap-network:
driver: "bridge"
Loading
Loading