Skip to content

Commit 167451e

Browse files
damirkaDamir
and
Damir
authored
[Sui System] Better Test Framework 2/N (#22084)
## Description Continues the journey to better tests for the System, adds extra cases on the way. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: --------- Co-authored-by: Damir <damir@Damirs-MacBook-Pro.local>
1 parent 2108d35 commit 167451e

10 files changed

+2221
-2003
lines changed

crates/sui-framework/packages/sui-system/tests/builders/test_runner.move

Lines changed: 209 additions & 25 deletions
Large diffs are not rendered by default.

crates/sui-framework/packages/sui-system/tests/builders/validator_builder.move

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
#[test_only]
5+
#[allow(unused_const)]
56
/// Validator Builder is a helper module which implements a builder pattern for
67
/// creating a `Validator` or `ValidatorMetadata` struct.
78
///
@@ -33,12 +34,33 @@ const VALID_ADDRESS: address = @0xaf76afe6f866d8426d2be85d6ef0b11f871a251d043b2f
3334
const VALID_PUBKEY: vector<u8> = x"99f25ef61f8032b914636460982c5cc6f134ef1ddae76657f2cbfec1ebfc8d097374080df6fcf0dcb8bc4b0d8e0af5d80ebbff2b4c599f54f42d6312dfc314276078c1cc347ebbbec5198be258513f386b930d02c2749a803e2330955ebd1a10";
3435
// prettier-ignore
3536
const PROOF_OF_POSSESSION: vector<u8> = x"b01cc86f421beca7ab4cfca87c0799c4d038c199dd399fbec1924d4d4367866dba9e84d514710b91feb65316e4ceef43";
36-
3737
const VALID_NET_ADDR: vector<u8> = b"/ip4/127.0.0.1/tcp/80";
3838
const VALID_P2P_ADDR: vector<u8> = b"/ip4/127.0.0.1/udp/80";
3939
const VALID_CONSENSUS_ADDR: vector<u8> = b"/ip4/127.0.0.1/udp/80";
4040
const VALID_WORKER_ADDR: vector<u8> = b"/ip4/127.0.0.1/udp/80";
4141

42+
// Each of the presets contains the following fields:
43+
// - Sui address
44+
// - Protocol pubkey
45+
// - Proof of possession
46+
// - Network pubkey
47+
// - Worker pubkey
48+
// - Network address
49+
// - P2P address
50+
// - Consensus address
51+
// - Worker address
52+
const VALIDATOR_PRESET_1: vector<vector<u8>> = vector[
53+
x"af76afe6f866d8426d2be85d6ef0b11f871a251d043b2f11e15563bf418f5a5a",
54+
VALID_PUBKEY,
55+
PROOF_OF_POSSESSION,
56+
VALID_NET_PUBKEY,
57+
VALID_WORKER_PUBKEY,
58+
VALID_NET_ADDR,
59+
VALID_P2P_ADDR,
60+
VALID_CONSENSUS_ADDR,
61+
VALID_WORKER_ADDR,
62+
];
63+
4264
/// Builder for a Validator. Contains all the fields that can be set for a
4365
/// validator with default stabs.
4466
public struct ValidatorBuilder has drop {
@@ -285,11 +307,19 @@ public fun commission_rate(mut builder: ValidatorBuilder, commission_rate: u64):
285307
builder
286308
}
287309

310+
/// Set the genesis stake for the validator.
288311
public fun initial_stake(mut builder: ValidatorBuilder, initial_stake: u64): ValidatorBuilder {
289312
builder.initial_stake = option::some(initial_stake);
290313
builder
291314
}
292315

316+
/// Try to set the genesis stake if it is not already set.
317+
/// Used by the `TestRunner` to set the initial stake for a validator in genesis.
318+
public fun try_initial_stake(mut builder: ValidatorBuilder, initial_stake: u64): ValidatorBuilder {
319+
if (builder.initial_stake.is_none()) builder.initial_stake.fill(initial_stake);
320+
builder
321+
}
322+
293323
public fun is_active_at_genesis(
294324
mut builder: ValidatorBuilder,
295325
is_active_at_genesis: bool,
@@ -300,6 +330,8 @@ public fun is_active_at_genesis(
300330

301331
// === Constants Access ===
302332

333+
public fun valid_protocol_pubkey(): vector<u8> { VALID_PUBKEY }
334+
303335
public fun valid_net_pubkey(): vector<u8> { VALID_NET_PUBKEY }
304336

305337
public fun valid_worker_pubkey(): vector<u8> { VALID_WORKER_PUBKEY }

0 commit comments

Comments
 (0)