Skip to content

Commit 458b669

Browse files
committed
Start using referee test elsewhere
1 parent 44f18b3 commit 458b669

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

src/tests/referee.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ use crate::common::types::{
1515
};
1616
use crate::referee::{RefereeMaker, ValidatorMoveArgs, GameMoveDetails};
1717

18-
struct DebugGamePrograms {
19-
my_validation_program: NodePtr,
20-
their_validation_program: NodePtr,
21-
my_turn_handler: GameHandler,
22-
their_turn_handler: GameHandler,
18+
pub struct DebugGamePrograms {
19+
pub my_validation_program: NodePtr,
20+
pub their_validation_program: NodePtr,
21+
pub my_turn_handler: GameHandler,
22+
pub their_turn_handler: GameHandler,
2323
}
2424

25-
fn make_debug_game_handler(
25+
pub fn make_debug_game_handler(
2626
allocator: &mut AllocEncoder,
2727
identity: &ChiaIdentity,
2828
amount: &Amount,
@@ -93,7 +93,7 @@ pub struct RefereeTest {
9393
}
9494

9595
impl RefereeTest {
96-
fn new(
96+
pub fn new(
9797
allocator: &mut AllocEncoder,
9898

9999
my_identity: ChiaIdentity,
@@ -205,7 +205,6 @@ fn test_referee_smoke() {
205205
&game_start_info,
206206
);
207207

208-
reftest.my_referee.enable_debug_run(true);
209208
let readable_move = assemble(allocator.allocator(), "(0 . 0)").expect("should assemble");
210209
let my_move_wire_data = reftest.my_referee
211210
.my_turn_make_move(

src/tests/simulator.rs

+61-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clvmr::allocator::NodePtr;
22
use clvm_traits::ToClvm;
33

4-
use clvm_tools_rs::classic::clvm_tools::binutils::disassemble;
4+
use clvm_tools_rs::classic::clvm_tools::binutils::{assemble, disassemble};
55

66
use pyo3::prelude::*;
77
use pyo3::types::{PyNone, PyBytes, PyTuple};
@@ -13,7 +13,11 @@ use indoc::indoc;
1313

1414
use crate::common::constants::{AGG_SIG_ME_ADDITIONAL_DATA, CREATE_COIN, DEFAULT_HIDDEN_PUZZLE_HASH};
1515
use crate::common::standard_coin::{sign_agg_sig_me, standard_solution_partial, ChiaIdentity, calculate_synthetic_secret_key, private_to_public_key, calculate_synthetic_public_key, agg_sig_me_message};
16-
use crate::common::types::{ErrToError, Error, Puzzle, Amount, Hash, CoinString, CoinID, PuzzleHash, PrivateKey, Aggsig, Node, SpecificTransactionBundle, AllocEncoder, TransactionBundle, ToQuotedProgram, Sha256tree};
16+
use crate::common::types::{ErrToError, Error, Puzzle, Amount, Hash, CoinString, CoinID, PuzzleHash, PrivateKey, Aggsig, Node, SpecificTransactionBundle, AllocEncoder, TransactionBundle, ToQuotedProgram, Sha256tree, Timeout, GameID};
17+
18+
use crate::channel_handler::types::GameStartInfo;
19+
20+
use crate::tests::referee::{RefereeTest, make_debug_game_handler};
1721

1822
// Allow simulator from rust.
1923
struct Simulator {
@@ -325,5 +329,59 @@ fn test_sim() {
325329

326330
#[test]
327331
fn test_referee_can_slash_on_chain() {
328-
332+
let seed: [u8; 32] = [0; 32];
333+
let mut rng = ChaCha8Rng::from_seed(seed);
334+
let mut allocator = AllocEncoder::new();
335+
336+
// Generate keys and puzzle hashes.
337+
let my_private_key: PrivateKey = rng.gen();
338+
let my_identity = ChiaIdentity::new(&mut allocator, my_private_key).expect("should generate");
339+
340+
let their_private_key: PrivateKey = rng.gen();
341+
let their_identity = ChiaIdentity::new(&mut allocator, their_private_key).expect("should generate");
342+
343+
let amount = Amount::new(100);
344+
let timeout = Timeout::new(1000);
345+
346+
let debug_game = make_debug_game_handler(
347+
&mut allocator,
348+
&my_identity,
349+
&amount,
350+
&timeout
351+
);
352+
let init_state =
353+
assemble(
354+
allocator.allocator(),
355+
"(0 . 0)"
356+
).expect("should assemble");
357+
358+
let my_validation_program_hash =
359+
Node(debug_game.my_validation_program).sha256tree(&mut allocator);
360+
361+
let amount = Amount::new(100);
362+
let game_start_info = GameStartInfo {
363+
game_id: GameID::from_bytes(b"test"),
364+
amount: amount.clone(),
365+
game_handler: debug_game.my_turn_handler,
366+
timeout: timeout.clone(),
367+
is_my_turn: true,
368+
initial_validation_puzzle: debug_game.my_validation_program,
369+
initial_validation_puzzle_hash: my_validation_program_hash,
370+
initial_state: init_state,
371+
initial_move: vec![],
372+
initial_max_move_size: 0,
373+
initial_mover_share: Amount::default(),
374+
};
375+
376+
let their_validation_program_hash =
377+
Node(debug_game.their_validation_program).sha256tree(&mut allocator);
378+
379+
let mut reftest = RefereeTest::new(
380+
&mut allocator,
381+
my_identity,
382+
their_identity,
383+
debug_game.their_turn_handler,
384+
their_validation_program_hash,
385+
&game_start_info,
386+
);
329387
}

0 commit comments

Comments
 (0)