universum 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,8 @@
7
7
  class Universum
8
8
 
9
9
  MAJOR = 0
10
- MINOR = 1
11
- PATCH = 2
10
+ MINOR = 2
11
+ PATCH = 0
12
12
  VERSION = [MAJOR,MINOR,PATCH].join('.')
13
13
 
14
14
  def self.version
@@ -1,18 +1,17 @@
1
1
  # encoding: utf-8
2
2
 
3
+ ######################
4
+ # Greeter Contract
3
5
 
4
- class Greeter < Contract
6
+ def initialize( greeting )
7
+ @owner = msg.sender
8
+ @greeting = greeting
9
+ end
5
10
 
6
- def initialize( greeting )
7
- @owner = msg.sender
8
- @greeting = greeting
9
- end
11
+ def greet
12
+ @greeting
13
+ end
10
14
 
11
- def greet
12
- @greeting
13
- end
14
-
15
- def kill
16
- selfdestruct( msg.sender ) if msg.sender == @owner
17
- end
18
- end # class Greeter
15
+ def kill
16
+ selfdestruct( msg.sender ) if msg.sender == @owner
17
+ end
@@ -1,20 +1,19 @@
1
1
  # encoding: utf-8
2
2
 
3
+ #########################
4
+ # My Token Contract
3
5
 
4
- class MyToken < Contract
6
+ def initialize( initial_supply )
7
+ @balance_of = Mapping.of( Address => Money )
8
+ @balance_of[ msg.sender] = initial_supply
9
+ end
5
10
 
6
- def initialize( initial_supply )
7
- @balance_of = Mapping.of( Address => Money )
8
- @balance_of[ msg.sender] = initial_supply
9
- end
11
+ def transfer( to, value )
12
+ assert @balance_of[ msg.sender ] >= value
13
+ assert @balance_of[ to ] + value >= @balance_of[ to ]
10
14
 
11
- def transfer( to, value )
12
- assert( @balance_of[ msg.sender ] >= value )
13
- assert( @balance_of[ to ] + value >= @balance_of[ to ] )
15
+ @balance_of[ msg.sender ] -= value
16
+ @balance_of[ to ] += value
14
17
 
15
- @balance_of[ msg.sender ] -= value
16
- @balance_of[ to ] += value
17
-
18
- true
19
- end
20
- end # class MyToken
18
+ true
19
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_array.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestArray < MiniTest::Test
12
+
13
+ Array_Integer = SafeArray.build_class( Integer )
14
+ Array_Bool = SafeArray.build_class( Bool )
15
+
16
+ def test_integer
17
+ pp Array_Integer
18
+ pp ary = Array_Integer.new
19
+
20
+ assert_equal Integer, Array_Integer.klass_value
21
+ assert_equal 0, ary[0]
22
+ assert_equal 0, ary[1]
23
+
24
+ ary[0] = 101
25
+ ary[1] = 102
26
+ assert_equal 101, ary[0]
27
+ assert_equal 102, ary[1]
28
+
29
+ ## check Array.of (uses cached classes)
30
+ assert_equal Array_Integer, Array.of( Integer ).class
31
+ end
32
+
33
+
34
+ def test_bool
35
+ pp Array_Bool
36
+ pp ary = Array_Bool.new
37
+
38
+ assert_equal Bool, Array_Bool.klass_value
39
+ assert_equal false, ary[0]
40
+ assert_equal false, ary[1]
41
+
42
+ ary[0] = true
43
+ ary[1] = true
44
+ assert_equal true, ary[0]
45
+ assert_equal true, ary[1]
46
+
47
+ ## check Array.of (uses cached classes)
48
+ assert_equal Array_Bool, Array.of( Bool ).class
49
+ end
50
+
51
+
52
+ end # class TestArray
data/test/test_greeter.rb CHANGED
@@ -8,11 +8,11 @@
8
8
  require 'helper'
9
9
 
10
10
 
11
- require 'contracts/greeter' ## use require_relative - why? why not?
12
-
13
11
 
14
12
  class TestGreeter < MiniTest::Test
15
13
 
14
+ Greeter = Contract.load( "#{Universum.root}/test/contracts/greeter" )
15
+
16
16
  def test_uni
17
17
  account = Account['0x1111']
18
18
 
data/test/test_hash.rb ADDED
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_hash.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestHash < MiniTest::Test
12
+
13
+ ## sig: [Integer, Bool, Integer, Address]
14
+ Voter = Struct.new( :weight, :voted, :vote, :delegate ) do
15
+ def self.new_zero
16
+ new( 0, false, 0, '0x0000' )
17
+ end
18
+ def self.zero
19
+ @zero ||= new_zero
20
+ end
21
+ end
22
+
23
+ Hash_X_Integer = SafeHash.build_class( String, Integer )
24
+ Hash_X_Bool = SafeHash.build_class( String, Bool )
25
+ Hash_X_Voter = SafeHash.build_class( String, Voter )
26
+
27
+ def test_integer
28
+ pp Hash_X_Integer
29
+ pp h = Hash_X_Integer.new
30
+
31
+ assert_equal Integer, Hash_X_Integer.klass_value
32
+ assert_equal 0, h['0x1111']
33
+ assert_equal 0, h['0x2222']
34
+
35
+ h['0x1111'] = 101
36
+ h['0x2222'] = 102
37
+ assert_equal 101, h['0x1111']
38
+ assert_equal 102, h['0x2222']
39
+
40
+ ## check Mapping.of (uses cached classes)
41
+ assert_equal Hash_X_Integer, Mapping.of( String => Integer ).class
42
+ end
43
+
44
+
45
+ def test_bool
46
+ pp Hash_X_Bool
47
+ pp h = Hash_X_Bool.new
48
+
49
+ assert_equal Bool, Hash_X_Bool.klass_value
50
+ assert_equal false, h['0x1111']
51
+ assert_equal false, h['0x2222']
52
+
53
+ h['0x1111'] = true
54
+ h['0x2222'] = true
55
+ assert_equal true, h['0x1111']
56
+ assert_equal true, h['0x2222']
57
+
58
+ ## check Mapping.of (uses cached classes)
59
+ assert_equal Hash_X_Bool, Mapping.of( String => Bool ).class
60
+ end
61
+
62
+
63
+ def test_voter
64
+ pp Hash_X_Voter
65
+ pp h = Hash_X_Voter.new
66
+
67
+ assert_equal Voter, Hash_X_Voter.klass_value
68
+ assert_equal Voter.zero, h['0x1111']
69
+ assert_equal Voter.zero, h['0x2222']
70
+
71
+ h['0x1111'].voted = true
72
+ h['0x2222'].voted = true
73
+ assert_equal true, h['0x1111'].voted
74
+ assert_equal true, h['0x2222'].voted
75
+
76
+ pp h['0x1111']
77
+ pp h['0x2222']
78
+
79
+ ## check Mapping.of (uses cached classes)
80
+ assert_equal Hash_X_Voter, Mapping.of( String => Voter ).class
81
+ end
82
+
83
+
84
+ end # class TestHash
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_struct.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestStruct < MiniTest::Test
12
+
13
+ ## sig: [Integer, Bool, Integer, Address]
14
+ Voter = Struct.new( :weight, :voted, :vote, :delegate ) do
15
+ def self.new_zero
16
+ new( 0, false, 0, '0x0000' )
17
+ end
18
+ def self.zero
19
+ @zero ||= new_zero
20
+ end
21
+ end
22
+
23
+
24
+ def test_zero
25
+ assert_equal Voter.zero, Voter.zero
26
+
27
+ zerodup = Voter.zero.dup
28
+ zerodup.delegate = '0x1111'
29
+ pp zerodup
30
+
31
+ assert_equal '0x0000', Voter.zero.delegate
32
+ end
33
+
34
+
35
+ end # class TestStruct
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_units_money.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestUnitsMoney < MiniTest::Test
12
+
13
+ def test_money
14
+ assert_equal 1_000_000_000_000_000_000, 1.e18
15
+ assert_equal 1_000_000_000_000_000, 1.e15
16
+ assert_equal 1_000_000_000_000, 1.e12
17
+ assert_equal 1_000_000_000, 1.e9
18
+ assert_equal 1_000_000, 1.e6
19
+ assert_equal 1_000, 1.e3
20
+
21
+
22
+ value = rand( 1_000_000_000 )
23
+
24
+ assert_equal 1_000_000_000_000_000_000, 1.ether
25
+ assert_equal 1_000_000_000_000_000_000, 1.eth
26
+ assert_equal 1_000_000_000_000_000_000*2, 1.ether*2
27
+ assert_equal value+1_000_000_000_000_000_000, value+1.ether
28
+
29
+ assert_equal 1_000_000_000_000_000, 1.milliether
30
+ assert_equal 1_000_000_000_000_000, 1.millieth
31
+ assert_equal 1_000_000_000_000_000, 1.milli
32
+ assert_equal 1_000_000_000_000_000, 1.finney
33
+ assert_equal 1_000_000_000_000_000*2, 1.milliether*2
34
+ assert_equal value+1_000_000_000_000_000, value+1.milliether
35
+
36
+ assert_equal 1_000_000_000_000, 1.microether
37
+ assert_equal 1_000_000_000_000, 1.microeth
38
+ assert_equal 1_000_000_000_000, 1.micro
39
+ assert_equal 1_000_000_000_000, 1.szabo
40
+ assert_equal 1_000_000_000_000*2, 1.microether*2
41
+ assert_equal value+1_000_000_000_000, value+1.microether
42
+
43
+ assert_equal 1_000_000_000, 1.gwei
44
+ assert_equal 1_000_000_000, 1.shannon
45
+ assert_equal 1_000_000_000*2, 1.gwei*2
46
+ assert_equal value+1_000_000_000, value+1.gwei
47
+
48
+ assert_equal 1_000_000, 1.mwei
49
+ assert_equal 1_000_000, 1.lovelace
50
+ assert_equal 1_000_000, 1.ada
51
+ assert_equal 1_000_000*2, 1.mwei*2
52
+ assert_equal value+1_000_000, value+1.mwei
53
+
54
+ assert_equal 1_000, 1.kwei
55
+ assert_equal 1_000, 1.babbage
56
+ assert_equal 1_000*2, 1.kwei*2
57
+ assert_equal value+1_000, value+1.kwei
58
+ end
59
+
60
+ end # class TestUnitsMoney
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_units_time.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestUnitsTime < MiniTest::Test
12
+
13
+ def test_time
14
+ now = Time.now.to_i
15
+
16
+ assert_equal 31_536_000, 1.year
17
+ assert_equal 31_536_000, 1.y
18
+ assert_equal 31_536_000*2, 2.years
19
+ assert_equal 31_536_000*2, 1.y*2
20
+ assert_equal now+31_536_000, now+1.year
21
+ assert_equal 31_536_000, 365.days
22
+ assert_equal 31_536_000, 365*24.hours
23
+
24
+ assert_equal 1_209_600, 1.fortnight
25
+ assert_equal 1_209_600*2, 2.fortnights
26
+ assert_equal 1_209_600*2, 1.fortnight*2
27
+ assert_equal now+1_209_600, now+1.fortnight
28
+ assert_equal 1_209_600, 2.weeks
29
+ assert_equal 1_209_600, 14.days
30
+ assert_equal 1_209_600, 14*24.hours
31
+
32
+ assert_equal 604_800, 1.week
33
+ assert_equal 604_800, 1.w
34
+ assert_equal 604_800*2, 2.weeks
35
+ assert_equal 604_800*2, 1.week*2
36
+ assert_equal now+604_800, now+1.week
37
+ assert_equal 604_800, 7.days
38
+ assert_equal 604_800, 7*24.hours
39
+
40
+ assert_equal 86_400, 1.day
41
+ assert_equal 86_400, 1.d
42
+ assert_equal 86_400*2, 2.days
43
+ assert_equal 86_400*2, 1.day*2
44
+ assert_equal now+86_400, now+1.day
45
+ assert_equal 86_400, 24.hours
46
+ assert_equal 86_400, 24*1.hour
47
+
48
+ assert_equal 3600, 1.hour
49
+ assert_equal 3600, 1.h
50
+ assert_equal 3600*2, 2.hours
51
+ assert_equal 3600*2, 1.hour*2
52
+ assert_equal now+3600, now+1.hour
53
+ assert_equal 3600, 60.minutes
54
+ assert_equal 3600, 60*1.minute
55
+
56
+ assert_equal 60, 1.minute
57
+ assert_equal 60, 1.min
58
+ assert_equal 60, 1.m
59
+ assert_equal 60*2, 2.minutes
60
+ assert_equal 60*2, 2.mins
61
+ assert_equal 60*2, 1.minute*2
62
+ assert_equal now+60, now+1.minute
63
+ assert_equal 60, 60.seconds
64
+ assert_equal 60, 60*1.second
65
+
66
+ assert_equal 1, 1.second
67
+ assert_equal 1, 1.sec
68
+ assert_equal 1, 1.s
69
+ assert_equal 1*2, 2.seconds
70
+ assert_equal 1*2, 2.secs
71
+ assert_equal 1*2, 1.second*2
72
+ assert_equal now+1, now+1.second
73
+ end
74
+
75
+ end # class TestUnitsTime
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: universum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-06 00:00:00.000000000 Z
11
+ date: 2019-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -57,18 +57,34 @@ files:
57
57
  - README.md
58
58
  - Rakefile
59
59
  - lib/universum.rb
60
+ - lib/universum/account.rb
61
+ - lib/universum/address.rb
62
+ - lib/universum/contract.rb
60
63
  - lib/universum/enum.rb
61
64
  - lib/universum/event.rb
65
+ - lib/universum/function.rb
66
+ - lib/universum/receipt.rb
67
+ - lib/universum/safe_array.rb
68
+ - lib/universum/safe_hash.rb
69
+ - lib/universum/transaction.rb
70
+ - lib/universum/type.rb
71
+ - lib/universum/units_money.rb
72
+ - lib/universum/units_time.rb
62
73
  - lib/universum/universum.rb
63
74
  - lib/universum/version.rb
64
75
  - test/contracts/greeter.rb
65
76
  - test/contracts/mytoken.rb
66
77
  - test/helper.rb
78
+ - test/test_array.rb
67
79
  - test/test_enum.rb
68
80
  - test/test_event.rb
69
81
  - test/test_greeter.rb
82
+ - test/test_hash.rb
83
+ - test/test_struct.rb
84
+ - test/test_units_money.rb
85
+ - test/test_units_time.rb
70
86
  - test/test_version.rb
71
- homepage: https://github.com/openblockchains/universum
87
+ homepage: https://github.com/s6ruby/universum
72
88
  licenses:
73
89
  - Public Domain
74
90
  metadata: {}