Skip to content

Commit bc89fab

Browse files
Merge pull request #87 from multiversx/feat/spica
Merge feat/spica into main
2 parents 26c328f + e17e8b7 commit bc89fab

108 files changed

Lines changed: 7043 additions & 1235 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Default (placeholder): mnemonic of "testwallets" (friends: Alice, Bob, Carol etc.):
2+
# https://github.com/multiversx/mx-sdk-testwallets/blob/main/users/mnemonic.txt.
3+
# This works fine for localnet.
4+
# For the Github workflows, a repository secret is being used.
5+
export USERS_MNEMONIC="moral volcano peasant pass circle pen over picture flat shop clap goat never lyrics gather prepare woman film husband gravity behind test tiger improve"
6+
7+
# Default (placeholder): Alice's secret key:
8+
# https://github.com/multiversx/mx-sdk-testwallets/blob/main/users/alice.pem.
9+
# This works fine for localnet.
10+
# For the Github workflows, a repository secret is being used.
11+
export SPONSOR_SECRET_KEY=413f42575f7f26fad3317a778771212fdb80245850981e48b58a4f25e344e8f9
12+
13+
# For the Github workflows, a repository secret (private deep history instance) is being used.
14+
export MAINNET_PROXY_URL="https://gateway.multiversx.com"

.github/workflows/check_with_mesh_cli.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
- name: Install dependencies
1919
run: |
20-
pip3 install requests bottle
20+
pip install -r ./requirements-dev.txt
2121
curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/master/scripts/install.sh | sh -s -- -b "$HOME/.local/bin"
2222
echo "$HOME/.local/bin" >> $GITHUB_PATH
2323
@@ -26,12 +26,26 @@ jobs:
2626
cd $GITHUB_WORKSPACE/cmd/rosetta && go build .
2727
cd $GITHUB_WORKSPACE/systemtests && go build ./proxyToObserverAdapter.go
2828
29-
- name: check:data
29+
- name: check:construction (native)
3030
run: |
31-
PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=data --network=testnet
31+
PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=construction-native --network=testnet
32+
sleep 30
33+
34+
- name: check:construction (custom)
35+
run: |
36+
PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=construction-custom --network=testnet
37+
sleep 30
3238
33-
- name: check:construction
39+
- name: Generate sample transactions for check:data
3440
run: |
35-
PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=construction --network=testnet
41+
PYTHONPATH=. python3 ./systemtests/generate_testdata_on_network.py setup --network=testnet
42+
PYTHONPATH=. python3 ./systemtests/generate_testdata_on_network.py run --network=testnet
43+
env:
44+
USERS_MNEMONIC: ${{ secrets.USERS_MNEMONIC }}
45+
SPONSOR_SECRET_KEY: ${{ secrets.SPONSOR_SECRET_KEY }}
46+
47+
- name: check:data
48+
run: |
49+
PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=data --network=testnet
3650
3751
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Check with Mesh CLI (mainnet)
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: 3.11
15+
16+
- uses: actions/checkout@v4
17+
18+
- name: Install dependencies
19+
run: |
20+
pip install -r ./requirements-dev.txt
21+
curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/master/scripts/install.sh | sh -s -- -b "$HOME/.local/bin"
22+
echo "$HOME/.local/bin" >> $GITHUB_PATH
23+
24+
- name: Build
25+
run: |
26+
cd $GITHUB_WORKSPACE/cmd/rosetta && go build .
27+
cd $GITHUB_WORKSPACE/systemtests && go build ./proxyToObserverAdapter.go
28+
29+
- name: check:data
30+
run: |
31+
PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=data --network=mainnet
32+
env:
33+
MAINNET_PROXY_URL: ${{ secrets.MAINNET_PROXY_URL }}
34+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
cmd/rosetta/rosetta
22
cmd/rosetta/logs/**
33
systemtests/logs/**
4+
systemtests/memento/**
45
systemtests/**/check-data/**
56
logs/**
67

78
**/__pycache__/**
9+
venv/**

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[json]": {
3+
"editor.tabSize": 4
4+
},
5+
"prettier"
6+
}

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,43 @@ oldest_block_identifier = first block of oldest_epoch
222222
- We do not support the `related_transactions` property, since it's not feasible to properly filter the related transactions of a given transaction by source / destination shard (with respect to the observed shard).
223223
- The endpoint `/block/transaction` is not implemented, since all transactions are returned by the endpoint `/block`.
224224
- We chose not to support the optional property `Operation.related_operations`. Although the smart contract results (also known as _unsigned transactions_) form a DAG (directed acyclic graph) at the protocol level, operations within a transaction are in a simple sequence.
225-
- Balance-changing operations that affect Smart Contract accounts are not emitted by our Rosetta implementation (thus are not available on the Rosetta API).
225+
- Balance-changing operations that affect Smart Contract accounts are only emitted if Rosetta is started with the flag `--handle-contracts`.
226226

227227
## Implementation validation
228228

229229
In order to validate the Rosetta implementation using `rosetta-cli`, please follow [MultiversX/rosetta-checks](https://github.com/multiversx/mx-chain-rosetta-checks).
230+
231+
## System tests
232+
233+
### Virtual environment
234+
235+
Create a virtual environment and install the dependencies:
236+
237+
```
238+
python3 -m venv ./venv
239+
source ./venv/bin/activate
240+
pip install -r ./requirements-dev.txt --upgrade
241+
```
242+
243+
### Check:data
244+
245+
Optional: generate sample data (transactions):
246+
247+
```
248+
source .env
249+
250+
PYTHONPATH=. python3 ./systemtests/generate_testdata_on_network.py setup --network testnet
251+
PYTHONPATH=. python3 ./systemtests/generate_testdata_on_network.py run --network testnet
252+
```
253+
254+
Run the checks:
255+
256+
```
257+
PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=data --network=testnet
258+
```
259+
260+
### Check:construction
261+
262+
```
263+
PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=construction-native --network=testnet
264+
```

cmd/rosetta/cli.go

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"math"
5+
46
logger "github.com/multiversx/mx-chain-logger-go"
57
"github.com/urfave/cli"
68
)
@@ -104,13 +106,13 @@ VERSION:
104106

105107
cliFlagMinGasPrice = cli.Uint64Flag{
106108
Name: "min-gas-price",
107-
Usage: "Specifies the minimum gas price (required in offline mode).",
109+
Usage: "Specifies the minimum gas price (for transaction construction).",
108110
Value: 1000000000,
109111
}
110112

111113
cliFlagMinGasLimit = cli.UintFlag{
112114
Name: "min-gas-limit",
113-
Usage: "Specifies the minimum gas limit (required in offline mode).",
115+
Usage: "Specifies the minimum gas limit (for transaction construction).",
114116
Value: 50000,
115117
}
116118

@@ -122,10 +124,22 @@ VERSION:
122124

123125
cliFlagGasPerDataByte = cli.UintFlag{
124126
Name: "gas-per-data-byte",
125-
Usage: "Specifies the gas required per data byte (required in offline mode).",
127+
Usage: "Specifies the gas required per data byte (for transaction construction).",
126128
Value: 1500,
127129
}
128130

131+
cliFlagGasPriceModifier = cli.Float64Flag{
132+
Name: "gas-price-modifier",
133+
Usage: "Specifies the gas price modifier (for transaction construction).",
134+
Value: 0.01,
135+
}
136+
137+
cliFlagGasLimitCustomTransfer = cli.Float64Flag{
138+
Name: "gas-limit-custom-transfer",
139+
Usage: "Specifies the necessary gas limit for a custom transfer (for transaction construction).",
140+
Value: 200000,
141+
}
142+
129143
cliFlagNativeCurrencySymbol = cli.StringFlag{
130144
Name: "native-currency",
131145
Usage: "Specifies the symbol of the native currency (must be EGLD for mainnet, XeGLD for testnet and devnet).",
@@ -143,6 +157,36 @@ VERSION:
143157
Usage: "Provides a hint for the number of historical epochs to be kept.",
144158
Required: true,
145159
}
160+
161+
cliFlagShouldHandleContracts = cli.BoolFlag{
162+
Name: "handle-contracts",
163+
Usage: "Whether to handle balance changes of smart contracts or not.",
164+
}
165+
166+
cliFlagConfigFileCustomCurrencies = cli.StringFlag{
167+
Name: "config-custom-currencies",
168+
Usage: "Specifies the configuration file for custom currencies.",
169+
Required: false,
170+
}
171+
172+
cliFlagActivationEpochSirius = cli.UintFlag{
173+
Name: "activation-epoch-sirius",
174+
Usage: "Specifies the activation epoch for Sirius release.",
175+
Required: false,
176+
Value: 1265,
177+
}
178+
179+
cliFlagActivationEpochSpica = cli.UintFlag{
180+
Name: "activation-epoch-spica",
181+
Usage: "Specifies the activation epoch for Spica release.",
182+
Required: false,
183+
Value: math.MaxUint32,
184+
}
185+
186+
cliFlagShouldEnablePprofEndpoints = cli.BoolFlag{
187+
Name: "pprof",
188+
Usage: "Whether to enable pprof HTTP endpoints.",
189+
}
146190
)
147191

148192
func getAllCliFlags() []cli.Flag {
@@ -164,9 +208,16 @@ func getAllCliFlags() []cli.Flag {
164208
cliFlagMinGasLimit,
165209
cliFlagExtraGasLimitGuardedTx,
166210
cliFlagGasPerDataByte,
211+
cliFlagGasPriceModifier,
212+
cliFlagGasLimitCustomTransfer,
167213
cliFlagNativeCurrencySymbol,
168214
cliFlagFirstHistoricalEpoch,
169215
cliFlagNumHistoricalEpochs,
216+
cliFlagShouldHandleContracts,
217+
cliFlagConfigFileCustomCurrencies,
218+
cliFlagActivationEpochSirius,
219+
cliFlagActivationEpochSpica,
220+
cliFlagShouldEnablePprofEndpoints,
170221
}
171222
}
172223

@@ -189,9 +240,16 @@ type parsedCliFlags struct {
189240
minGasLimit uint64
190241
extraGasLimitGuardedTx uint64
191242
gasPerDataByte uint64
243+
gasPriceModifier float64
244+
gasLimitCustomTransfer uint64
192245
nativeCurrencySymbol string
193246
firstHistoricalEpoch uint32
194247
numHistoricalEpochs uint32
248+
shouldHandleContracts bool
249+
configFileCustomCurrencies string
250+
activationEpochSirius uint32
251+
activationEpochSpica uint32
252+
shouldEnablePprofEndpoints bool
195253
}
196254

197255
func getParsedCliFlags(ctx *cli.Context) parsedCliFlags {
@@ -214,8 +272,15 @@ func getParsedCliFlags(ctx *cli.Context) parsedCliFlags {
214272
minGasLimit: ctx.GlobalUint64(cliFlagMinGasLimit.Name),
215273
extraGasLimitGuardedTx: ctx.GlobalUint64(cliFlagExtraGasLimitGuardedTx.Name),
216274
gasPerDataByte: ctx.GlobalUint64(cliFlagGasPerDataByte.Name),
275+
gasPriceModifier: ctx.GlobalFloat64(cliFlagGasPriceModifier.Name),
276+
gasLimitCustomTransfer: ctx.GlobalUint64(cliFlagGasLimitCustomTransfer.Name),
217277
nativeCurrencySymbol: ctx.GlobalString(cliFlagNativeCurrencySymbol.Name),
218278
firstHistoricalEpoch: uint32(ctx.GlobalUint(cliFlagFirstHistoricalEpoch.Name)),
219279
numHistoricalEpochs: uint32(ctx.GlobalUint(cliFlagNumHistoricalEpochs.Name)),
280+
shouldHandleContracts: ctx.GlobalBool(cliFlagShouldHandleContracts.Name),
281+
configFileCustomCurrencies: ctx.GlobalString(cliFlagConfigFileCustomCurrencies.Name),
282+
activationEpochSirius: uint32(ctx.GlobalUint(cliFlagActivationEpochSirius.Name)),
283+
activationEpochSpica: uint32(ctx.GlobalUint(cliFlagActivationEpochSpica.Name)),
284+
shouldEnablePprofEndpoints: ctx.GlobalBool(cliFlagShouldEnablePprofEndpoints.Name),
220285
}
221286
}

cmd/rosetta/config.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
8+
"github.com/multiversx/mx-chain-rosetta/server/resources"
9+
)
10+
11+
func decideCustomCurrencies(configFileCustomCurrencies string) ([]resources.Currency, error) {
12+
if len(configFileCustomCurrencies) == 0 {
13+
return make([]resources.Currency, 0), nil
14+
}
15+
16+
return loadConfigOfCustomCurrencies(configFileCustomCurrencies)
17+
}
18+
19+
func loadConfigOfCustomCurrencies(configFile string) ([]resources.Currency, error) {
20+
fileContent, err := os.ReadFile(configFile)
21+
if err != nil {
22+
return nil, fmt.Errorf("error when reading custom currencies config file: %w", err)
23+
}
24+
25+
var customCurrencies []resources.Currency
26+
27+
err = json.Unmarshal(fileContent, &customCurrencies)
28+
if err != nil {
29+
return nil, fmt.Errorf("error when loading custom currencies from file: %w", err)
30+
}
31+
32+
return customCurrencies, nil
33+
}

cmd/rosetta/config_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/multiversx/mx-chain-rosetta/server/resources"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestDecideCustomCurrencies(t *testing.T) {
11+
t.Run("with success (file provided)", func(t *testing.T) {
12+
customCurrencies, err := decideCustomCurrencies("testdata/custom-currencies.json")
13+
require.NoError(t, err)
14+
require.Len(t, customCurrencies, 2)
15+
})
16+
17+
t.Run("with success (file not provided)", func(t *testing.T) {
18+
customCurrencies, err := decideCustomCurrencies("")
19+
require.NoError(t, err)
20+
require.Empty(t, customCurrencies)
21+
})
22+
}
23+
24+
func TestLoadConfigOfCustomCurrencies(t *testing.T) {
25+
t.Run("with success", func(t *testing.T) {
26+
customCurrencies, err := loadConfigOfCustomCurrencies("testdata/custom-currencies.json")
27+
require.NoError(t, err)
28+
require.NoError(t, err)
29+
require.Equal(t, []resources.Currency{
30+
{
31+
Symbol: "WEGLD-bd4d79",
32+
Decimals: 18,
33+
},
34+
{
35+
Symbol: "USDC-c76f1f",
36+
Decimals: 6,
37+
},
38+
}, customCurrencies)
39+
})
40+
41+
t.Run("with error (missing file)", func(t *testing.T) {
42+
_, err := loadConfigOfCustomCurrencies("testdata/missing-file.json")
43+
require.ErrorContains(t, err, "error when reading custom currencies config file")
44+
})
45+
46+
t.Run("with error (invalid file)", func(t *testing.T) {
47+
_, err := loadConfigOfCustomCurrencies("testdata/custom-currencies-bad.json")
48+
require.ErrorContains(t, err, "error when loading custom currencies from file")
49+
})
50+
}

0 commit comments

Comments
 (0)