1
1
use clvmr:: allocator:: NodePtr ;
2
2
use clvm_traits:: ToClvm ;
3
3
4
- use clvm_tools_rs:: classic:: clvm_tools:: binutils:: disassemble;
4
+ use clvm_tools_rs:: classic:: clvm_tools:: binutils:: { assemble , disassemble} ;
5
5
6
6
use pyo3:: prelude:: * ;
7
7
use pyo3:: types:: { PyNone , PyBytes , PyTuple } ;
@@ -13,7 +13,11 @@ use indoc::indoc;
13
13
14
14
use crate :: common:: constants:: { AGG_SIG_ME_ADDITIONAL_DATA , CREATE_COIN , DEFAULT_HIDDEN_PUZZLE_HASH } ;
15
15
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} ;
17
21
18
22
// Allow simulator from rust.
19
23
struct Simulator {
@@ -325,5 +329,59 @@ fn test_sim() {
325
329
326
330
#[ test]
327
331
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
+ ) ;
329
387
}
0 commit comments