Skip to content

Commit

Permalink
Add support for new vara-testnet (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitry Osipov <[email protected]>
  • Loading branch information
stefanmendoza-cb and osipov-mit authored Oct 10, 2023
1 parent 052a2fa commit 1ffb83e
Show file tree
Hide file tree
Showing 24 changed files with 453 additions and 411 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ jobs:
run: node ./test/set-prefunded-acc.js ./dev.json ./test/development/config.json

- name: Run Gear node
run: nohup ./gear --chain ./dev.json --alice --tmp --pruning archive --execution=wasm --unsafe-ws-external --unsafe-rpc-external --rpc-methods Unsafe --rpc-cors all &

- name: Sleep
run: sleep 10
run: nohup ./gear --chain ./dev.json --validator --alice --tmp --pruning archive --unsafe-ws-external --unsafe-rpc-external --rpc-methods Unsafe --rpc-cors all &

- name: Make transfers
run: node ./test/make-transfers.js

- name: Update development config
run: node ./util/cli/app.js update config/development.json -a http://127.0.0.1:9933
run: node ./util/cli/app.js update config/rosetta/gear-development.json -a http://127.0.0.1:9933

- name: Run server in online mode
run: yarn start:dev --update-config &
Expand All @@ -63,5 +60,9 @@ jobs:
- name: Run check:data
run: ./bin/rosetta-cli --configuration-file ./test/development/config.json check:data

- name: Find out the balance of the prefunded account
run: |
curl -L 'http://127.0.0.1:8080/account/balance' -H 'Content-Type: application/json' -d '{"account_identifier": {"address": "kGkfymFqB4aBVunXCW69EzQRDtkZkUQB44GB4XJnwNwqmWyRN"},"network_identifier": {"blockchain": "gear","network": "development"}}'
- name: Run check:construction
run: ./bin/rosetta-cli --configuration-file ./test/development/config.json check:construction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Build image rosseta:copyvara'
name: 'Build image rosetta:testnet'

on:
workflow_dispatch:
Expand Down Expand Up @@ -35,9 +35,9 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Rosetta image for copyvara
- name: Build and push Rosetta image for testnet
uses: docker/build-push-action@master
with:
file: Dockerfile-copyvara
file: Dockerfile-testnet
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:copyvara
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:testnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Renew CapyVara
name: Renew Vara Testnet

on:
workflow_dispatch:
Expand All @@ -7,7 +7,7 @@ on:


env:
BRANCH_PREFIX: update-config-capyvara
BRANCH_PREFIX: update-config-testnet
CARGO_TERM_COLOR: always
TERM: xterm-256color

Expand All @@ -24,15 +24,15 @@ jobs:
id: compare
run: |
# Check Genesis and SpecVersion
RenewedGenesis=$(curl -X POST https://dev-archive-staking.vara-network.io -H 'Content-Type: application/json' -d '[ { "id": 1, "jsonrpc": "2.0", "method": "chain_getBlockHash", "params": [0]}]' | jq -r '.[].result');
RenewedSpecVersion=$(curl -X POST https://dev-archive-staking.vara-network.io -H 'Content-Type: application/json' -d '[ { "id": 1, "jsonrpc": "2.0", "method": "state_getRuntimeVersion", "params": []}]' | jq -r '.[].result.specVersion');
RenewedGenesis=$(curl -X POST https://testnet-archive.vara-network.io -H 'Content-Type: application/json' -d '[ { "id": 1, "jsonrpc": "2.0", "method": "chain_getBlockHash", "params": [0]}]' | jq -r '.[].result');
RenewedSpecVersion=$(curl -X POST https://testnet-archive.vara-network.io -H 'Content-Type: application/json' -d '[ { "id": 1, "jsonrpc": "2.0", "method": "state_getRuntimeVersion", "params": []}]' | jq -r '.[].result.specVersion');
# Read previous Genesis and SpecVersion from file
originalgenesis=$(sed '1!d' spec-capyvara.info)
originalspecVersion=$(sed '2!d' spec-capyvara.info)
originalgenesis=$(sed '1!d' spec-testnet.info)
originalspecVersion=$(sed '2!d' spec-testnet.info)
NewValue="$RenewedGenesis\n$RenewedSpecVersion"
# Compare
if [ "$originalspecVersion" -ne "$RenewedSpecVersion" ] || [ "$originalgenesis" != "$RenewedGenesis" ]
then echo "Spec or Genesis change" && echo -e "$NewValue" > spec-capyvara.info && echo "::set-output name=metaChanged::true"
then echo "Spec or Genesis change" && echo -e "$NewValue" > spec-testnet.info && echo "::set-output name=metaChanged::true"
else echo "Spec and Genesis haven't changed"
fi
Expand All @@ -49,7 +49,7 @@ jobs:
- name: Renew vara config
if: ${{ steps.compare.outputs.metaChanged == 'true' }}
working-directory: util
run: yarn update:vara-test
run: yarn update:vara-testnet

- name: New PR branch
if: ${{ steps.compare.outputs.metaChanged == 'true' }}
Expand All @@ -63,13 +63,13 @@ jobs:
id: cpr
uses: peter-evans/create-pull-request@v4
with:
commit-message: add new capyvara config
commit-message: add new testnet config
branch: ${{ steps.new-branch.outputs.name }}
delete-branch: true
base: master
title: '[Automated] Renew capyvara config'
title: '[Automated] Renew testnet config'
add-paths: |
spec-capyvara.info
spec-testnet.info
config/*
body: |
New vara config
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile-copyvara → Dockerfile-testnet
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ RUN useradd -m -u 1000 -U -s /bin/sh -d /gear gear && \
USER root

# Copy conf files
COPY mini-vara.json /opt/mini-vara.json
COPY supervisord-copyvara.conf /etc/supervisor/conf.d/supervisord.conf
COPY config/rosetta/testnet.json /opt/testnet.json
COPY supervisord-testnet.conf /etc/supervisor/conf.d/supervisord.conf

EXPOSE 8080
CMD [ "/usr/bin/supervisord"]
96 changes: 0 additions & 96 deletions config/development.json

This file was deleted.

189 changes: 189 additions & 0 deletions config/gear/vara-testnet.json

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions config/rosetta/gear-development.json

Large diffs are not rendered by default.

File renamed without changes.
73 changes: 73 additions & 0 deletions config/rosetta/vara-testnet.json

Large diffs are not rendered by default.

73 changes: 0 additions & 73 deletions config/vara-test.json

This file was deleted.

175 changes: 0 additions & 175 deletions mini-vara.json

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"start:dev": "yarn workspace rosetta-api run start:dev",
"start:offline": "yarn workspace rosetta-api run start:offline",
"start:vara": "yarn workspace rosetta-api run start:vara",
"start:vara-test": "yarn workspace rosetta-api run start:vara-test",
"start:vara-testnet": "yarn workspace rosetta-api run start:vara-testnet",
"watch:dev": "yarn workspace rosetta-api run watch:dev",
"watch:vara": "yarn workspace rosetta-api run watch:vara",
"watch:vara-test": "yarn workspace rosetta-api run watch:vara-test",
"watch:vara-testnet": "yarn workspace rosetta-api run watch:vara-testnet",
"watch:offline": "yarn workspace rosetta-api run watch:offline"
},
"packageManager": "[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"scripts": {
"start:dev": "node dist/index.js --config-name development",
"start:vara": "node dist/index.js --config-name vara",
"start:vara-test": "node dist/index.js --config-name vara_testnet",
"start:vara-testnet": "node dist/index.js --config-name vara_testnet",
"start:offline": "node dist/index.js --mode offline",
"watch:dev": "nodemon src/index.ts --config-name development",
"watch:vara": "nodemon src/index.ts --config-name vara",
"watch:vara-test": "nodemon src/index.ts --config-name vara_testnet",
"watch:vara-testnet": "nodemon src/index.ts --config-name vara_testnet",
"watch:offline": "nodemon src/index.ts --mode offline",
"build": "rm -rf dist && tsc",
"lint": "yarn run eslint src/**/*.ts"
Expand Down
2 changes: 1 addition & 1 deletion server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
ROSETTA_VERSION: '1.4.13',
MODE,
CONFIG_NAME,
CONFIG_DIR: opts.configsDir ? path.resolve(process.cwd(), opts.configsDir) : '../config',
CONFIG_DIR: opts.configsDir ? path.resolve(process.cwd(), opts.configsDir) : '../config/rosetta',
WS: opts.ws,
HTTP: opts.http,
UPDATE_CONFIG: opts.updateConfig,
Expand Down
2 changes: 0 additions & 2 deletions spec-capyvara.info

This file was deleted.

2 changes: 2 additions & 0 deletions spec-testnet.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0x525639f713f397dcf839bd022cd821f367ebcf179de7b9253531f8adbe5436d6
1000
10 changes: 0 additions & 10 deletions supervisord-copyvara.conf

This file was deleted.

10 changes: 10 additions & 0 deletions supervisord-testnet.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[supervisord]
nodaemon=true

[program:gear-testnet]
directory=/opt/rosetta-api
command=/usr/local/bin/gear --base-path /data/ --chain /opt/vara-testnet.json --unsafe-ws-external --unsafe-rpc-external --rpc-methods Unsafe --rpc-cors all --pruning archive --name=gear-vara

[program:rosetta]
directory=/opt/rosetta-api
command=yarn start:vara-testnet --update-config --ws ws://localhost:9944 --http http://localhost:9933
6 changes: 3 additions & 3 deletions test/development/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"network": {
"blockchain": "gear",
"blockchain": "vara",
"network": "development"
},
"online_url": "http://localhost:8080",
Expand Down Expand Up @@ -32,11 +32,11 @@
{
"privkey": "345ec9a5f329ccb38fe0004fd14496f9a2c983caf146a8ba2b082535f4a4cf7c",
"account_identifier": {
"address": "5HChDnRNd2xn7rGsbJNqJrV5NmpALVKTY9YC2Zzeyu5rjzqC"
"address": "kGkfymFqB4aBVunXCW69EzQRDtkZkUQB44GB4XJnwNwqmWyRN"
},
"curve_type": "edwards25519",
"currency": {
"symbol": "GRT",
"symbol": "VARA",
"decimals": 12
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/development/gear.ros
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
create_account(1){
create{
network = {"network":"development", "blockchain":"gear"};
network = {"network":"development", "blockchain":"vara"};
key = generate_key({"curve_type": "edwards25519"});
account = derive({
"network_identifier": {{network}},
Expand All @@ -16,17 +16,17 @@ create_account(1){

transfer(1){
transfer{
transfer.network = {"network":"development", "blockchain":"gear"};
currency = {"symbol":"GRT", "decimals":12};
transfer.network = {"network":"development", "blockchain":"vara"};
currency = {"symbol":"VARA", "decimals":12};

sender = find_balance({
"minimum_balance":{
"value": "10000",
"value": "20000000000000",
"currency": {{currency}}
}
});

recipient_amount = random_number({"minimum": "1000", "maximum": "5000"});
recipient_amount = random_number({"minimum": "10000000000000", "maximum": "50000000000000"});
sender_amount = 0 - {{recipient_amount}};
print_message({"sender":{{sender.account_identifier}}, "amount":{{sender_amount}}});

Expand Down
33 changes: 27 additions & 6 deletions test/make-transfers.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
const { ApiPromise } = require('@polkadot/api');
const { Keyring } = require('@polkadot/keyring');


const main = async () => {
const api = await ApiPromise.create();
const keyring = new Keyring();
const alice = keyring.addFromUri('//Alice', {}, 'sr25519');
const bob = keyring.addFromUri('//Bob', {}, 'sr25519');

await api.tx.balances.transferKeepAlive('5HChDnRNd2xn7rGsbJNqJrV5NmpALVKTY9YC2Zzeyu5rjzqC', 100000).signAndSend(alice)
await api.tx.balances.transferKeepAlive('5GDCKqWHVg6NG9RQeKQjAQ7t9Pc94UZ3FsxRDCNyesUudi8Y', 100000).signAndSend(bob)
}
const tx = api.tx.utility.batchAll([
api.tx.balances.transferKeepAlive('kGkfymFqB4aBVunXCW69EzQRDtkZkUQB44GB4XJnwNwqmWyRN', 1000 * 10 ** 12),
api.tx.balances.transferKeepAlive('kGjgUsJv5wDK645fjZ7B8qx42fNMjCPQdmzbHhwBG3vEpQhij', 100 * 10 ** 12),
]);

await new Promise((resolve, reject) =>
tx.signAndSend(alice, ({ events, status }) => {
if (status.isInBlock) {
const transferEvents = events.filter(
({ event: { method, section } }) => section === 'balances' && method === 'Transfer',
);

if (transferEvents.length > 0) {
transferEvents.forEach((transferEvent) => {
const [from, to, amount] = transferEvent.event.data;
console.log(`${from} transfered ${amount} to ${to}`);
});
} else {
console.log('No transfer event found');
}
} else if (status.isFinalized) {
resolve('Finalized');
}
}),
);
};

main()
.then(() => process.exit(0))
.catch((error) => {
console.log(error);
console.log(error);
process.exit(1);
});

22 changes: 14 additions & 8 deletions test/set-prefunded-acc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ assert.notStrictEqual(path, undefined, 'Path to gear spec file is not specified'
assert.notStrictEqual(configPath, undefined, 'Path to rosetta config file is not specified');

let spec = fs.readFileSync(path, 'utf-8');
let config = fs.readFileSync(configPath, 'utf-8');
const accounts = JSON.parse(config).construction.prefunded_accounts.map(({ account_identifier: { address }}) =>
` [

const prefunded = ['5HChDnRNd2xn7rGsbJNqJrV5NmpALVKTY9YC2Zzeyu5rjzqC'];

const accounts = prefunded
.map(
(address) =>
` [
"${address}",
1152921504606846976
10000000000000000
]
`).join(',\n');
`,
)
.join(',\n');

const balance = `,
${accounts}
]
}`;

const match = spec.match(/"balances": \[[\w\W]+?\}/g)[0]
json = spec.replace(match, match.replace(/\s*\]\s*\}/g, balance))
const match = spec.match(/"balances": \[[\w\W]+?\}/g)[0];
json = spec.replace(match, match.replace(/\s*\]\s*\}/g, balance));

fs.writeFileSync(path, json)
fs.writeFileSync(path, json);
6 changes: 3 additions & 3 deletions util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
},
"scripts": {
"build": "rm -rf dist && tsc",
"update:dev": "node ./cli/app.js update ../config/development.json -a http://127.0.0.1:9933",
"update:vara": "node ./cli/app.js update ../config/vara.json -a https://rpc.vara-network.io",
"update:vara-test": "node ./cli/app.js update ../config/vara-test.json -a https://dev-rpc-staking.vara-network.io"
"update:dev": "node ./cli/app.js update ../config/rosetta/gear-development.json -a http://127.0.0.1:9933",
"update:vara": "node ./cli/app.js update ../config/rosetta/vara-mainnet.json -a https://rpc.vara-network.io",
"update:vara-testnet": "node ./cli/app.js update ../config/rosetta/vara-testnet.json -a https://testnet-archive.vara-network.io"
}
}
6 changes: 3 additions & 3 deletions util/src/getChainParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export async function getChainParams(address: string): Promise<IParams> {
// }
case 5: {
params.properties = {
ss58Format: result.ss58format || 42,
ss58Format: result.ss58format || 137,
tokenDecimals: result.tokenDecimals || 12,
tokenSymbol: result.tokenSymbol || 'GRT',
tokenSymbol: result.tokenSymbol || 'VARA',
};
params.ss58Format = result.ss58format || 42;
params.ss58Format = result.ss58format || 137;
break;
}
}
Expand Down

0 comments on commit 1ffb83e

Please sign in to comment.