-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_satoshidice.rb
66 lines (45 loc) · 1.5 KB
/
run_satoshidice.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
##
# to run use:
# $ ruby run_satoshidice.rb
require_relative 'helper'
require_relative 'satoshidice'
pp SathoshiDice
contract = SathoshiDice.new
pp contract
puts "serialize:"
pp contract.serialize
alice = '0x'+'a'*40 # e.g. '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
bob = '0x'+'b'*40 # e.g. '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
charlie = '0x'+'c'*40 # e.g. '0xcccccccccccccccccccccccccccccccccccccccc'
Simulacrum.msg.sender = alice
contract = SathoshiDice.construct
pp contract.__address__
pp contract
puts "serialize:"
pp contract.serialize
#=> {:owner=>"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
# :counter=>0,
# :bets=>{}}
Simulacrum.block.number = 888
Simulacrum.msg.sender = bob
Simulacrum.msg.value = 100
contract.bet( cap: 1000 ) ## cap max. 65_536 = 2^16 = 2 byte/16 bit
pp contract
puts "serialize:"
pp contract.serialize
#=> {:owner=>"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
# :counter=>1,
# :bets=>{1=>["0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 891, 1000, 100]}}
Simulacrum.block.number = 889
Simulacrum.msg.sender = charlie
Simulacrum.msg.value = 200
contract.bet( cap: 10000 )
pp contract
puts "serialize:"
pp contract.serialize
#=> {:owner=>"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
# :counter=>2,
# :bets=>
# {1=>["0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 891, 1000, 100],
# 2=>["0xcccccccccccccccccccccccccccccccccccccccc", 892, 10000, 200]}}
puts 'bye'