Skip to content

Commit 26c8dfb

Browse files
authored
added mock farm service (#303)
1 parent 5e7e5fe commit 26c8dfb

File tree

32 files changed

+1140
-32
lines changed

32 files changed

+1140
-32
lines changed

Cargo.lock

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"info": {
3+
"_postman_id": "a54a9a24-ef93-48b5-a447-09a5d61d5075",
4+
"name": "Mock Farm",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
6+
"_exporter_id": "11181958"
7+
},
8+
"item": [
9+
{
10+
"name": "List all active environments",
11+
"request": {
12+
"method": "GET",
13+
"header": [],
14+
"url": {
15+
"raw": "https://127.0.0.1:7070/api/v0/active",
16+
"protocol": "https",
17+
"host": [
18+
"127",
19+
"0",
20+
"0",
21+
"1"
22+
],
23+
"port": "7070",
24+
"path": [
25+
"api",
26+
"v0",
27+
"active"
28+
]
29+
}
30+
},
31+
"response": []
32+
},
33+
{
34+
"name": "Start new environment with name 'marek' and port = 10010",
35+
"request": {
36+
"method": "POST",
37+
"header": [],
38+
"url": {
39+
"raw": "https://127.0.0.1:7070/api/v0/start/darek",
40+
"protocol": "https",
41+
"host": [
42+
"127",
43+
"0",
44+
"0",
45+
"1"
46+
],
47+
"port": "7070",
48+
"path": [
49+
"api",
50+
"v0",
51+
"start",
52+
"darek"
53+
]
54+
}
55+
},
56+
"response": []
57+
},
58+
{
59+
"name": "Shutdown existing environment with name 'marek'",
60+
"request": {
61+
"method": "POST",
62+
"header": [],
63+
"url": {
64+
"raw": "https://127.0.0.1:7070/api/v0/start/marek/10010",
65+
"protocol": "https",
66+
"host": [
67+
"127",
68+
"0",
69+
"0",
70+
"1"
71+
],
72+
"port": "7070",
73+
"path": [
74+
"api",
75+
"v0",
76+
"start",
77+
"marek",
78+
"10010"
79+
]
80+
}
81+
},
82+
"response": []
83+
},
84+
{
85+
"name": "Shutdown existing environment with name 'marek'",
86+
"request": {
87+
"method": "POST",
88+
"header": [],
89+
"url": {
90+
"raw": "https://127.0.0.1:7070/api/v0/shutdown/marek",
91+
"protocol": "https",
92+
"host": [
93+
"127",
94+
"0",
95+
"0",
96+
"1"
97+
],
98+
"port": "7070",
99+
"path": [
100+
"api",
101+
"v0",
102+
"shutdown",
103+
"marek"
104+
]
105+
}
106+
},
107+
"response": []
108+
}
109+
]
110+
}

doc/api/vitup/mock-farm/v0.yaml

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
openapi: 3.0.2
2+
3+
info:
4+
title: Mock farm REST API
5+
description: Mock Farm Rest API v0
6+
version: 0.0.1
7+
contact:
8+
url: 'https://github.com/input-output-hk/vit-testing/'
9+
10+
servers:
11+
- url: 'https://localhost'
12+
13+
tags:
14+
- name: active
15+
- name: start
16+
- name: shutdown
17+
18+
paths:
19+
'/api/v0/active':
20+
get:
21+
description: Lists active mock environments
22+
operationId: Active
23+
tags:
24+
- active
25+
responses:
26+
'200':
27+
description: Success
28+
content:
29+
application/json:
30+
schema:
31+
description: assigned port number
32+
type: string
33+
format: text
34+
'400':
35+
description: Mock env with given ID or port already exists
36+
37+
'/api/v0/start/{env_name}':
38+
post:
39+
description: Starts new mock env with random free port
40+
operationId: StartEnvRandomPort
41+
tags:
42+
- start
43+
parameters:
44+
- name: env_name
45+
in: path
46+
required: true
47+
schema:
48+
description: Environment name
49+
type: string
50+
pattern: '[0-9a-f]+'
51+
responses:
52+
'200':
53+
description: Success
54+
content:
55+
application/json:
56+
schema:
57+
description: assigned port number
58+
type: string
59+
format: text
60+
'400':
61+
description: Mock env with given ID or port already exists
62+
63+
'/api/v0/start/{env_name}/{port}':
64+
post:
65+
description: Starts new mock env with random free port
66+
operationId: StartEnv
67+
tags:
68+
- start
69+
parameters:
70+
- name: env_name
71+
in: path
72+
required: true
73+
schema:
74+
description: Environment name
75+
type: string
76+
pattern: '[0-9a-f]+'
77+
responses:
78+
'200':
79+
description: Success
80+
content:
81+
application/json:
82+
schema:
83+
description: assigned port number
84+
type: string
85+
format: text
86+
'400':
87+
description: Mock env with given ID or port already exists
88+
89+
'/api/v0/shutdown/{env_name}':
90+
post:
91+
description: Shutdown new mock env with random free port
92+
operationId: ShutdownEnv
93+
tags:
94+
- shutdown
95+
parameters:
96+
- name: env_name
97+
in: path
98+
required: true
99+
schema:
100+
description: Environment name
101+
type: string
102+
pattern: '[0-9a-f]+'
103+
responses:
104+
'200':
105+
description: Success
106+
content:
107+
application/json:
108+
schema:
109+
description: assigned port number
110+
type: string
111+
format: text
112+
'404':
113+
description: Mock env with given ID was not found

doc/vitup/mock_farm.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
## Mock Farm
3+
4+
Mock farm is a simple extension for mock service. It allows to run more that one mock at once and give more control to user in term of starting and stopping particular mock instance.
5+
6+
### Configuration
7+
8+
This section describe configuration file which can be passed as argument for snapshot service:
9+
10+
- `port`: port on which registration-service will be exposed,
11+
- `working_directory`: path to folder which config files will be dumped,
12+
- `mocks-port-range`: range of ports assigned for usage,
13+
- `protocol`: decide whether mock farm should be exposed as http or https,
14+
- `local`: should service be exposed on all network interfaces or only 127.0.0.1,
15+
- `token`: token limiting access to environment. Must be provided in header `API-Token` for each request
16+
17+
Note: it is recommended to run command from `vit-testing/vitup` folder (then no explicit paths are required to be provided).
18+
Configuration file example is available under `vit-testing/vitup/example/mock-farm/config.yaml`
19+
20+
### Start
21+
22+
`vitup start mock-farm --config example\mock\mock-farm\config.yaml`
23+
24+
### Documentation
25+
26+
- [OpenApi](../api/vitup/mock-farm/v0.yaml)
27+
- [Requests collection](../api/vitup/mock-farm/postman_collection.json)
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use catalyst_toolbox::snapshot::CatalystRegistration;
2+
use chain_addr::Discrimination;
3+
use jormungandr_lib::crypto::account::SigningKey;
4+
use vitup::config::Block0Initial;
5+
6+
pub struct MainnetWallet {
7+
inner: thor::Wallet,
8+
reward_address: String,
9+
stake_public_key: String,
10+
stake: u64,
11+
}
12+
13+
impl MainnetWallet {
14+
pub fn new(stake: u64) -> Self {
15+
let mut rng = rand::thread_rng();
16+
Self {
17+
inner: thor::Wallet::new_account(&mut rng, Discrimination::Production),
18+
stake,
19+
reward_address: "0x".to_owned()
20+
+ &SigningKey::generate_extended(&mut rng)
21+
.identifier()
22+
.to_hex(),
23+
stake_public_key: "0x".to_owned()
24+
+ &SigningKey::generate_extended(&mut rng)
25+
.identifier()
26+
.to_hex(),
27+
}
28+
}
29+
30+
pub fn reward_address(&self) -> String {
31+
self.reward_address.clone()
32+
}
33+
34+
pub fn stake_public_key(&self) -> String {
35+
self.stake_public_key.clone()
36+
}
37+
38+
pub fn catalyst_secret_key(&self) -> chain_crypto::SecretKey<chain_crypto::Ed25519Extended> {
39+
self.inner.secret_key()
40+
}
41+
42+
pub fn as_voting_registration(&self) -> CatalystRegistration {
43+
CatalystRegistration {
44+
stake_public_key: self.stake_public_key(),
45+
voting_power: self.stake.into(),
46+
reward_address: self.reward_address(),
47+
voting_public_key: self.inner.identifier().into(),
48+
}
49+
}
50+
51+
pub fn as_initial_entry(&self) -> Block0Initial {
52+
Block0Initial::External {
53+
address: self.inner.address().to_string(),
54+
funds: self.stake,
55+
role: Default::default(),
56+
}
57+
}
58+
}

integration-tests/src/e2e/local/active_voters_rewards.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ pub fn voters_with_at_least_one_vote() {
156156
}
157157
acc
158158
});
159-
160-
(Identifier::from_bech32_str(id).unwrap(), votes)
159+
(Identifier::from_hex(id).unwrap(), votes)
161160
})
162161
.collect();
163162

mainnet-tools/src/db_sync/mod.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,10 @@ impl DbSyncInstance {
3636
}
3737
}
3838

39-
#[derive(Debug, Clone)]
39+
#[derive(Debug, Clone, Default)]
4040
pub struct Settings {
4141
pub db_name: String,
4242
pub db_user: String,
4343
pub db_host: String,
44-
}
45-
46-
impl Default for Settings {
47-
fn default() -> Self {
48-
Self {
49-
db_name: "mock".to_string(),
50-
db_user: "mock".to_string(),
51-
db_host: "mock".to_string(),
52-
}
53-
}
44+
pub db_pass: String,
5445
}

mainnet-tools/src/voting_tools/command.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub struct VotingToolsCommand {
1919
#[structopt(long = "db-user")]
2020
pub db_user: String,
2121

22+
#[structopt(long = "db-pass")]
23+
pub db_pass: String,
24+
2225
#[structopt(long = "db-host")]
2326
pub db_host: PathBuf,
2427

0 commit comments

Comments
 (0)