@@ -8,7 +8,7 @@ use clvm_tools_rs::classic::clvm_tools::binutils::{assemble, disassemble};
8
8
9
9
use crate :: channel_handler:: game_handler:: GameHandler ;
10
10
use crate :: channel_handler:: types:: { GameStartInfo , ReadableMove } ;
11
- use crate :: common:: standard_coin:: read_hex_puzzle;
11
+ use crate :: common:: standard_coin:: { private_to_public_key , read_hex_puzzle, puzzle_hash_for_pk } ;
12
12
use crate :: common:: types:: {
13
13
Aggsig , AllocEncoder , Amount , Error , GameID , Node , PrivateKey , PuzzleHash , Sha256tree , Timeout ,
14
14
} ;
@@ -45,31 +45,54 @@ fn test_referee_smoke() {
45
45
let seed: [ u8 ; 32 ] = [ 0 ; 32 ] ;
46
46
let mut rng = ChaCha8Rng :: from_seed ( seed) ;
47
47
let mut allocator = AllocEncoder :: new ( ) ;
48
- let referee_coin_puzzle_hash: PuzzleHash = rng. gen ( ) ;
49
- let private_key: PrivateKey = rng. gen ( ) ;
50
- let their_puzzle_hash: PuzzleHash = rng. gen ( ) ;
51
- let nil = allocator. allocator ( ) . null ( ) ;
52
- let val_hash = Node ( nil) . sha256tree ( & mut allocator) ;
53
- let init_state = assemble ( allocator. allocator ( ) , "(0 . 0)" ) . expect ( "should assemble" ) ;
48
+
49
+ // Load up the real referee coin.
50
+ let referee_coin_puzzle = read_hex_puzzle ( & mut allocator, "onchain/referee.hex" ) . expect ( "should be readable" ) ;
51
+ let referee_coin_puzzle_hash: PuzzleHash = referee_coin_puzzle. sha256tree ( & mut allocator) ;
52
+
53
+ // Generate keys and puzzle hashes.
54
+ let my_private_key: PrivateKey = rng. gen ( ) ;
55
+ let my_public_key = private_to_public_key ( & my_private_key) ;
56
+ let my_puzzle_hash = puzzle_hash_for_pk ( & mut allocator, & my_public_key) . expect ( "should have" ) ;
57
+
58
+ let their_private_key: PrivateKey = rng. gen ( ) ;
59
+ let their_public_key = private_to_public_key ( & their_private_key) ;
60
+ let their_puzzle_hash: PuzzleHash = puzzle_hash_for_pk ( & mut allocator, & their_public_key) . expect ( "should have" ) ;
61
+
62
+ let amount = Amount :: new ( 100 ) ;
63
+
64
+ let debug_game_handler = make_debug_game_handler ( & mut allocator, & amount) ;
65
+ let validation_program = CurriedProgram {
66
+ program : Node ( debug_game_handler. to_nodeptr ( ) ) ,
67
+ args : clvm_curried_args ! ( 1337 )
68
+ } . to_clvm ( & mut allocator) . expect ( "should curry" ) ;
69
+ let init_state =
70
+ assemble (
71
+ allocator. allocator ( ) ,
72
+ "(0 . 0)"
73
+ ) . expect ( "should assemble" ) ;
74
+
75
+ let validation_program_hash = Node ( validation_program) . sha256tree ( & mut allocator) ;
76
+
54
77
let amount = Amount :: new ( 100 ) ;
55
78
let game_start_info = GameStartInfo {
56
79
game_id : GameID :: from_bytes ( b"test" ) ,
57
80
amount : amount. clone ( ) ,
58
- game_handler : make_debug_game_handler ( & mut allocator , & amount ) ,
81
+ game_handler : debug_game_handler ,
59
82
timeout : Timeout :: new ( 1000 ) ,
60
83
is_my_turn : true ,
61
- initial_validation_puzzle : nil ,
62
- initial_validation_puzzle_hash : val_hash ,
84
+ initial_validation_puzzle : validation_program ,
85
+ initial_validation_puzzle_hash : validation_program_hash ,
63
86
initial_state : init_state,
64
87
initial_move : vec ! [ 0 , 0 ] ,
65
88
initial_max_move_size : 0 ,
66
89
initial_mover_share : Amount :: default ( ) ,
67
90
} ;
68
91
let mut referee = RefereeMaker :: new (
69
92
& mut allocator,
70
- referee_coin_puzzle_hash,
93
+ referee_coin_puzzle_hash. clone ( ) ,
71
94
& game_start_info,
72
- & private_key ,
95
+ & my_private_key ,
73
96
& their_puzzle_hash,
74
97
1 ,
75
98
)
@@ -100,10 +123,12 @@ fn test_referee_smoke() {
100
123
assert ! ( false ) ;
101
124
}
102
125
126
+ let on_chain_cheat = referee. clone ( ) ;
127
+
103
128
let their_move_result = referee
104
129
. their_turn_move_off_chain (
105
130
& mut allocator,
106
- & [ 0 ] ,
131
+ & [ ] ,
107
132
& my_move_result. validation_info_hash ,
108
133
100 ,
109
134
& Amount :: default ( ) ,
@@ -114,4 +139,13 @@ fn test_referee_smoke() {
114
139
disassemble( allocator. allocator( ) , their_move_result. readable_move, None ) ,
115
140
"(())"
116
141
) ;
142
+
143
+ let mut their_referee = RefereeMaker :: new (
144
+ & mut allocator,
145
+ referee_coin_puzzle_hash,
146
+ & game_start_info,
147
+ & their_private_key,
148
+ & their_puzzle_hash,
149
+ 1 ,
150
+ ) ;
117
151
}
0 commit comments