-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrun_satoshi_dice.rb
41 lines (27 loc) · 1.09 KB
/
run_satoshi_dice.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
# encoding: utf-8
require 'universum'
require_relative './satoshi_dice'
## setup test accounts with starter balance
Account[ '0x1111' ].balance = 1_000
Account[ '0xaaaa' ].balance = 1_000
Account[ '0xbbbb' ].balance = 1_000
Account[ '0xcccc' ].balance = 1_000
## pretty print (pp) all known accounts with balance
pp Uni.accounts
## genesis - create contract
dice = Uni.send_transaction( from: '0x1111', data: SatoshiDice ).contract
pp dice
Uni.send_transaction( from: '0x1111', to: dice, value: 1_000, data: [:fund] )
pp dice
Uni.send_transaction( from: '0xaaaa', to: dice, value: 100, data: [:bet, 20_000] )
pp dice
Uni.send_transaction( from: '0xbbbb', to: dice, value: 100, data: [:bet, 30_000] )
pp dice
## "mine" some blocks - block number (height) set to 3 and timestamp to Time.now
Uni.block = { timestamp: Time.now.to_i, number: 3 }
Uni.send_transaction( from: '0xaaaa', to: dice, data: [:roll, 1] )
pp dice
Uni.send_transaction( from: '0xbbbb', to: dice, data: [:roll, 2] )
pp dice
## pretty print (pp) all known accounts with balance
pp Uni.accounts