-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_PunksV1.rb
105 lines (70 loc) · 2.04 KB
/
test_PunksV1.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
###
# to run use (in /punks):
# $ ruby test_PunksV1.rb
$LOAD_PATH.unshift( '../solidity-typed/lib' )
$LOAD_PATH.unshift( '../rubysol/lib' )
require 'rubysol'
require_relative 'PunksV1' # punks contract
pp Punks
pp Punks.name
pp Punks::Assign
pp Punks::Transfer
pp Punks::PunkTransfer
pp Punks::PunkOffered
pp Punks::PunkBought
pp Punks::PunkNoLongerForSale
pp Punks::Offer
pp Punks::Assign.name
pp Punks::Transfer.name
pp Punks::PunkTransfer.name
pp Punks::PunkOffered.name
pp Punks::PunkBought.name
pp Punks::PunkNoLongerForSale.name
pp Punks::Offer.name
ALICE = '0x'+'a'*40 # e.g. '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
BOB = '0x'+'b'*40
CHARLIE = '0x'+'c'*40
pp ALICE
pp BOB
pp CHARLIE
Runtime.msg.sender = ALICE
punks = Punks.construct
pp punks
pp punks.serialize
#=> {:owner=>"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
# :name=>"PUNKS",
# :symbol=>"P",
# :decimals=>0,
# :totalSupply=>10000,
# :nextPunkIndexToAssign=>0,
# :punksRemainingToAssign=>10000,
# :numberOfPunksToReserve=>1000,
# :numberOfPunksReserved=>0,
# :punkIndexToAddress=>{},
# :balanceOf=>{},
# :punksOfferedForSale=>{},
# :pendingWithdrawals=>{}}
pp punks.name
pp punks.symbol
pp punks.decimals
pp punks.totalSupply
pp punks.balanceOf( ALICE )
punks.reservePunksForOwner( 100 )
pp punks.nextPunkIndexToAssign #=> 100
pp punks.punksRemainingToAssign #=> 9900
Runtime.msg.sender = BOB
punks.getPunk( 100 )
punks.getPunk( 101 )
punks.getPunk( 102 )
# note: nextPunkIndexToAssign only gets updated in reservePunksForOwner
pp punks.nextPunkIndexToAssign #=> 100
pp punks.punksRemainingToAssign #=> 9897
pp punks.balanceOf( ALICE ) #=> 100
pp punks.balanceOf( BOB ) #=> 3
Runtime.msg.sender = ALICE
punks.transferPunk( to: CHARLIE, punkIndex: 99 )
pp punks.balanceOf( ALICE ) #=> 99
pp punks.balanceOf( BOB ) #=> 3
pp punks.balanceOf( CHARLIE ) #=> 1
pp punks.serialize
puts "bye"