Skip to content

Commit e2a6bcf

Browse files
committed
More code running
1 parent f6f6798 commit e2a6bcf

File tree

5 files changed

+45
-12
lines changed

5 files changed

+45
-12
lines changed

resources/debug_game_handler.clsp

+11-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222
)
2323

2424
(defun get-move-share (new-move)
25-
(substr new-move 1 (- (strlen new-move 1)))
25+
(assign
26+
len (strlen new-move)
27+
(if (> len 1)
28+
(substr new-move 1 (strlen new-move))
29+
()
30+
)
31+
)
2632
)
2733

2834
(defun validation_program (validation-data)
@@ -51,22 +57,23 @@
5157
(c set_share set_cheated)
5258
100
5359
set_share
54-
(curry MOD_HASH PUZZLE AMOUNT (not MY_TURN) SLASH_INFO)
60+
(curry PUZZLE MOD_HASH PUZZLE AMOUNT (not MY_TURN) SLASH_INFO)
5561
()
5662
)
5763
)
5864
)
5965

6066
(defun do_their_turn (MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO amount last_state new_move new_validation_info_hash new_max_move_size new_mover_share)
6167
(assign
62-
set_cheated (substr new_move 0 1)
68+
set_cheated (+ (substr new_move 0 1))
6369

6470
(if set_cheated
6571
(c 2 SLASH_INFO)
6672
(list
6773
0
6874
(c set_cheated (get-move-share new_move)) ;; readable move
69-
(curry PUZZLE PUZZLE AMOUNT (not MY_TURN) SLASH_INFO)
75+
(curry PUZZLE MOD_HASH PUZZLE AMOUNT (not MY_TURN) SLASH_INFO)
76+
"message data"
7077
)
7178
)
7279
)

resources/debug_game_handler.hex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ff02ffff01ff02ffff03ff2fffff01ff02ff10ffff04ff02ffff04ff05ffff04ff0bffff04ff17ffff04ff2fffff04ff5fff7f80808080808080ffff01ff02ff14ffff04ff02ffff04ff05ffff04ff0bffff04ff17ffff04ff2fffff04ff5fff7f8080808080808080ff0180ffff04ffff01ffffffff02ff18ffff04ff02ffff04ff03ffff04ff8200bfffff04ffff02ff2effff04ff02ffff04ff8202ffffff04ffff019174686973206973206e6f74207269676874ff8080808080ff808080808080ff04ffff0effff02ff2affff04ff02ffff04ff1bff80808080ff1380ffff04ffff04ffff0102ffff04ffff04ffff0101ff3e80ffff04ffff04ffff0104ffff04ffff04ffff0101ff0280ffff04ffff0101ff80808080ff80808080ffff04ff17ffff04ffff04ff13ff1b80ffff04ffff0164ffff04ff13ffff04ffff02ff16ffff04ff02ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff8080808080808080ffff04ff80ff808080808080808080ffff02ff2cffff04ff02ffff04ff03ffff04ffff0cff8202ffff80ffff010180ff8080808080ffff02ffff03ff0bffff01ff04ffff0102ff8200bd80ffff01ff04ff80ffff04ffff04ff0bffff02ff3cffff04ff02ffff04ff8205fdff8080808080ffff04ffff02ff16ffff04ff02ffff04ff15ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff8080808080808080ff8080808080ff0180ff0cff05ffff0101ffff11ffff0dff05ffff0101808080ffff82017fffff03ff05ff05ffff010080ff02ffff03ff05ffff01ff04ffff0104ffff04ffff04ffff0101ff0980ffff04ffff02ff3affff04ff02ffff04ff0dff80808080ff80808080ffff01ff010180ff0180ffff04ffff0102ffff04ffff04ffff0101ff0580ffff04ffff02ff3affff04ff02ffff04ff07ff80808080ff80808080ffff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff2effff04ff02ffff04ff09ff80808080ffff02ff2effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff02ffff03ffff0cffff02ff12ffff04ff02ffff04ff05ff80808080ff80ffff010180ffff01ff08ffff019b76616c69646174696f6e2070726f6772616d206368656174696e67ff0580ffff01ff018080ff0180ff018080
1+
ff02ffff01ff02ffff03ff2fffff01ff02ff10ffff04ff02ffff04ff05ffff04ff0bffff04ff17ffff04ff2fffff04ff5fff7f80808080808080ffff01ff02ff38ffff04ff02ffff04ff05ffff04ff0bffff04ff17ffff04ff2fffff04ff5fff7f8080808080808080ff0180ffff04ffff01ffffffff02ff28ffff04ff02ffff04ff03ffff04ff8200bfffff04ffff02ff2effff04ff02ffff04ff8202ffffff04ffff019174686973206973206e6f74207269676874ff8080808080ff808080808080ffff04ffff0effff02ff2affff04ff02ffff04ff1bff80808080ff1380ffff04ffff04ffff0102ffff04ffff04ffff0101ff3e80ffff04ffff04ffff0104ffff04ffff04ffff0101ff0280ffff04ffff0101ff80808080ff80808080ffff04ff17ffff04ffff04ff13ff1b80ffff04ffff0164ffff04ff13ffff04ffff02ff16ffff04ff02ffff04ff15ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff808080808080808080ffff04ff80ff808080808080808080ff02ff14ffff04ff02ffff04ff03ffff04ffff10ffff0cff8202ffff80ffff01018080ff8080808080ffff02ffff03ff0bffff01ff04ffff0102ff8200bd80ffff01ff04ff80ffff04ffff04ff0bffff02ff2cffff04ff02ffff04ff8205fdff8080808080ffff04ffff02ff16ffff04ff02ffff04ff15ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff808080808080808080ffff04ffff018c6d6573736167652064617461ff808080808080ff0180ffff02ff3cffff04ff02ffff04ff03ffff04ffff0dff0580ff8080808080ff02ffff03ffff15ff0bffff010180ffff01ff0cff09ffff0101ff0b80ffff01ff018080ff0180ffff82017fffff03ff05ff05ffff010080ff02ffff03ff05ffff01ff04ffff0104ffff04ffff04ffff0101ff0980ffff04ffff02ff3affff04ff02ffff04ff0dff80808080ff80808080ffff01ff010180ff0180ffff04ffff0102ffff04ffff04ffff0101ff0580ffff04ffff02ff3affff04ff02ffff04ff07ff80808080ff80808080ffff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff2effff04ff02ffff04ff09ff80808080ffff02ff2effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff02ffff03ffff0cffff02ff12ffff04ff02ffff04ff05ff80808080ff80ffff010180ffff01ff08ffff019b76616c69646174696f6e2070726f6772616d206368656174696e67ff0580ffff01ff018080ff0180ff018080

src/channel_handler/game_handler.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use clvm_tools_rs::compiler::clvm::{convert_to_clvm_rs, convert_from_clvm_rs, ru
1616
use clvm_tools_rs::compiler::comptypes::CompilerOpts;
1717
#[cfg(test)]
1818
use clvm_tools_rs::compiler::srcloc::Srcloc;
19-
use clvm_traits::ToClvm;
19+
use clvm_traits::{ToClvm, ClvmEncoder};
2020

2121
use crate::common::types::{AllocEncoder, Amount, Error, Hash, Aggsig, usize_from_atom, u64_from_atom, Node, IntoErr, atom_from_clvm};
2222
use crate::channel_handler::types::{ReadableMove, ReadableUX};
@@ -283,7 +283,7 @@ impl GameHandler {
283283
let driver_args =
284284
(inputs.amount.clone(),
285285
(Node(inputs.last_state.clone()),
286-
(inputs.new_move.clone(),
286+
(Node(allocator.encode_atom(inputs.new_move).into_gen()?),
287287
(inputs.new_validation_info_hash.clone(),
288288
(inputs.new_max_move_size.clone(),
289289
(inputs.new_mover_share.clone(), ())))))
@@ -317,12 +317,12 @@ impl GameHandler {
317317

318318
if move_type == 0 {
319319
if pl.len() != 4 {
320-
return Err(Error::StrErr("bad length".to_string()));
320+
return Err(Error::StrErr(format!("bad length for move result {}", disassemble(allocator.allocator(), run_result, None))));
321321
}
322322
Ok(TheirTurnResult::MakeMove(GameHandler::my_driver_from_nodeptr(pl[2]), pl[1], allocator.allocator().atom(pl[3]).to_vec()))
323323
} else if move_type == 2 {
324324
if pl.len() != 3 {
325-
return Err(Error::StrErr(format!("bad length {}", disassemble(allocator.allocator(), run_result, None))));
325+
return Err(Error::StrErr(format!("bad length for slash {}", disassemble(allocator.allocator(), run_result, None))));
326326
}
327327
let sig_bytes = allocator.allocator().atom(pl[2]).to_vec();
328328
Ok(TheirTurnResult::Slash(pl[1], Aggsig::from_slice(&sig_bytes)?))

src/referee/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct RefereeMakerGameState {
126126
// Referee coin has two inner puzzles.
127127
// Throughout channel handler, the one that's ours is the standard format puzzle
128128
// to the pubkey of the referee private key (referred to in channel_handler).
129+
#[derive(Clone)]
129130
pub struct RefereeMaker {
130131
pub referee_coin_puzzle_hash: PuzzleHash,
131132
pub my_private_key: PrivateKey,

src/tests/referee.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use rand_chacha::ChaCha8Rng;
44
use clvm_traits::{clvm_curried_args, ToClvm};
55
use clvm_utils::CurriedProgram;
66

7-
use clvm_tools_rs::classic::clvm_tools::binutils::assemble;
7+
use clvm_tools_rs::classic::clvm_tools::binutils::{assemble, disassemble};
88

9-
use crate::common::types::{GameID, Timeout, Amount, PuzzleHash, PrivateKey, AllocEncoder, Sha256tree, Node};
9+
use crate::common::types::{GameID, Timeout, Amount, PuzzleHash, PrivateKey, AllocEncoder, Sha256tree, Node, Aggsig, Error};
1010
use crate::common::standard_coin::read_hex_puzzle;
1111
use crate::channel_handler::game_handler::GameHandler;
1212
use crate::channel_handler::types::{GameStartInfo, ReadableMove};
@@ -21,14 +21,15 @@ fn make_debug_game_handler(
2121
"resources/debug_game_handler.hex"
2222
).expect("should be readable");
2323
let game_handler_mod_hash = debug_game_handler.sha256tree(allocator);
24+
let aggsig = Aggsig::default();
2425
let curried_game_handler = CurriedProgram {
2526
program: debug_game_handler.clone(),
2627
args: clvm_curried_args!(
2728
game_handler_mod_hash,
2829
debug_game_handler,
2930
amount.clone(),
3031
true,
31-
((), ()) // slash info
32+
((), (aggsig, ())) // slash info
3233
)
3334
};
3435
GameHandler::my_driver_from_nodeptr(curried_game_handler.to_clvm(allocator).expect("should curry"))
@@ -84,4 +85,28 @@ fn test_referee_smoke() {
8485
&ReadableMove::from_nodeptr(readable_move)
8586
).expect("should move");
8687
assert_eq!(my_move_result.move_made, &[0]);
88+
let mut off_chain_slash_gives_error = referee.clone();
89+
let their_move_result = off_chain_slash_gives_error.their_turn_move_off_chain(
90+
&mut allocator,
91+
&[1],
92+
&my_move_result.validation_info_hash,
93+
100,
94+
&Amount::default()
95+
);
96+
if let Err(Error::StrErr(s)) = their_move_result {
97+
assert!(s.contains("slash"));
98+
assert!(s.contains("off chain"));
99+
} else {
100+
assert!(false);
101+
}
102+
103+
let their_move_result = referee.their_turn_move_off_chain(
104+
&mut allocator,
105+
&[0],
106+
&my_move_result.validation_info_hash,
107+
100,
108+
&Amount::default()
109+
).expect("should run");
110+
assert_eq!(their_move_result.message, b"message data");
111+
assert_eq!(disassemble(allocator.allocator(), their_move_result.readable_move, None), "(())");
87112
}

0 commit comments

Comments
 (0)