etherdev 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dd7bd0d64b923a8a4ea59a6c7a900251ac5e39c2
4
+ data.tar.gz: e67ec6b68b67adb44a29d9e68c92b22442555d69
5
+ SHA512:
6
+ metadata.gz: 82d2898e5906f563f0b660ad4429c37584507bef4b000de72c485e105debfa06710bcc65702934fd384becbbb63dc61b95d88e33641486f40f91c42230e65ea4
7
+ data.tar.gz: ad96e5ff8691137adc6f2731a64759277100746def29faadc29a52cf45bb4407c61dfc42a724630fe92f7260290cefb259485bd7cc03364a13fb424741c8ee82
@@ -0,0 +1,41 @@
1
+ # Welcome to EtherDev
2
+
3
+ EtherDev is an Ethereum blockchain development toolkit that includes everything you need to compile, test, and deploy Ethereum Smart Contracts.
4
+
5
+ EtherDev lets you develop and test your Solidity Smart Contracts with your favorite language and testing framework: Ruby and MiniTest. Developing and testing your contracts will feel very similar as developing other Ruby frameworks and libraries, like for example Ruby on Rails.
6
+
7
+ ## Getting Started
8
+
9
+ 1. Install EtherDev at the command prompt if you haven't yet:
10
+
11
+ ```
12
+ $ gem install etherdev
13
+ ```
14
+
15
+ 2. At the command prompt, create a new EtherDev project:
16
+ ```
17
+ $ etherdev new myproject
18
+ ```
19
+
20
+ where "myproject" is your desired new project name.
21
+
22
+ 3. Install and run the Ganache personal development Ethereum blockchain
23
+
24
+ Go to http://truffleframework.com/ganache/ and install Ganache for your platform. Then run a personal blockchain on your machine for fast and easy
25
+ testing of your contracts.
26
+
27
+ 4. Change directory to `myproject` and run the sample contract:
28
+
29
+ ```
30
+ $ cd myproject
31
+ $ bin/rake
32
+ ```
33
+
34
+ Congratulations! You've compiled, deploy and tested the functionality of the
35
+ Greeter contract that's available by default in your project. You can now add
36
+ your other contracts to the `contracts/` folder and add your tests for them to
37
+ `tests/`.
38
+
39
+ ## License
40
+
41
+ EtherDev is released under the [MIT License](https://opensource.org/licenses/MIT)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require "thor"
3
+ require "ether_dev"
4
+
5
+ EtherDev::CLI.start(ARGV)
@@ -0,0 +1,7 @@
1
+ require "eth"
2
+ require "ethereum.rb"
3
+ require "yaml"
4
+ require "rake"
5
+ require "thor"
6
+
7
+ require "ether_dev/cli"
@@ -0,0 +1,25 @@
1
+ module EtherDev
2
+ class CLI < Thor
3
+ desc "deploy FILE [private key]", "compiles a contract via Solidity"
4
+ def deploy(filename, private_key = nil)
5
+ config = YAML.load(File.open("config.yml"))["development"] || {}
6
+
7
+ key = ::Eth::Key.new priv: (private_key || config["account_key"])
8
+ client = Ethereum::HttpClient.new(config["rpc"])
9
+
10
+ contract = Ethereum::Contract.create(file: "contracts/#{filename}", client: client)
11
+ contract.key = key
12
+ puts "Deploying contract..."
13
+ contract.deploy_and_wait()
14
+ puts "Deployed contract to #{contract.address}"
15
+ end
16
+
17
+ desc "new PROJECTNAME", "generates a new EtherDev project PROJECTNAME"
18
+ def new(project_name)
19
+ require "ether_dev/generators/project_generator"
20
+
21
+ generator = ProjectGenerator.new(project_name)
22
+ generator.generate
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,73 @@
1
+ require "ether_dev/generators/project_templates"
2
+
3
+ module EtherDev
4
+ class ProjectGenerator
5
+ include ProjectTemplates
6
+
7
+ def initialize(project_name)
8
+ @project_name = project_name
9
+ end
10
+
11
+ def generate
12
+ $stdout.sync = true
13
+ create_directory(@project_name)
14
+ create_file(project_templates["Gemfile"], @project_name, "Gemfile")
15
+ create_file(project_templates["Rakefile"], @project_name, "Rakefile")
16
+
17
+ create_directory(@project_name, "contracts")
18
+ create_file(project_templates["Greeter.sol"], @project_name, "contracts", "Greeter.sol")
19
+
20
+ create_directory(@project_name, "config")
21
+ create_file(project_templates["blockchain.yml"], @project_name, "config", "blockchain.yml")
22
+
23
+ create_directory(@project_name, "test")
24
+ create_file(project_templates["test_helper.rb"], @project_name, "test", "test_helper.rb")
25
+
26
+ create_directory(@project_name, "test", "contracts")
27
+ create_file(project_templates["greeter_test.rb"], @project_name, "test", "contracts", "greeter_test.rb")
28
+
29
+ run_bundler
30
+
31
+ puts
32
+ puts
33
+ puts <<~EOF
34
+ 🎉🎉🎉 Get started with EtherDev\n
35
+
36
+ Your new EtherDev project is now generated. Now start Ganache and run
37
+ the following command to compile, deploy and test the example Greeter.sol
38
+ contract:
39
+
40
+ $ bundle exec rake
41
+
42
+ Check out the Wiki for next steps:
43
+ https://github.com/michiels/ruby-etherdev/wiki
44
+ EOF
45
+ end
46
+
47
+ private
48
+
49
+ def create_directory(directory_name, *args)
50
+ directory_path = File.join([directory_name] + args)
51
+ FileUtils.mkdir_p(directory_path)
52
+ puts "- Created #{directory_path}"
53
+ end
54
+
55
+ def create_file(template, directory_name, *args)
56
+ filepath = File.join([directory_name] + args)
57
+ File.open(filepath, "w+") do |f|
58
+ f.write template
59
+ end
60
+ puts "- Generated file #{filepath}"
61
+ end
62
+
63
+ def run_bundler
64
+ puts
65
+ puts "Running bundler..."
66
+ IO.popen("cd #{@project_name} && bundle install") do |io|
67
+ while (line = io.gets) do
68
+ puts line
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,77 @@
1
+ module EtherDev
2
+ module ProjectTemplates
3
+ def project_templates
4
+ templates = {}
5
+ templates["Gemfile"] = <<~'EOS'
6
+ gem "etherdev"
7
+ gem "ethereum.rb", github: "michiels/ethereum.rb", branch: "fixes-for-etherdev"
8
+ EOS
9
+
10
+ templates["Rakefile"] = <<~'EOS'
11
+ spec = Gem::Specification.find_by_name 'etherdev'
12
+ load "#{spec.gem_dir}/lib/ether_dev/test_task.rake"
13
+ EOS
14
+
15
+ templates["blockchain.yml"] = <<~'EOS'
16
+ # You can use the Project Orca test Ethereum blockchain to easily
17
+ # test and stage your contracts and interact with them in your team
18
+ # or from other deployed apps.
19
+ #
20
+ # Sign up at https://projectorca.net and uncomment the following:
21
+ #
22
+ # development:
23
+ # rpc: https://rpc.projectorca.net
24
+ # # Put your private account key here:
25
+ # account_key: c38dbe6e3725e012ec5e1d114ccc9061bb02946e5efdd1b2c7e0856897cfa0ef
26
+ test:
27
+ rpc: http://localhost:7545
28
+ EOS
29
+
30
+ templates["Greeter.sol"] = <<~'EOS'
31
+ contract mortal {
32
+ /* Define variable owner of the type address */
33
+ address owner;
34
+
35
+ /* This function is executed at initialization and sets the owner of the contract */
36
+ function mortal() { owner = msg.sender; }
37
+
38
+ /* Function to recover the funds on the contract */
39
+ function kill() { if (msg.sender == owner) selfdestruct(owner); }
40
+ }
41
+
42
+ contract greeter is mortal {
43
+ /* Define variable greeting of the type string */
44
+ string greeting;
45
+
46
+ /* This runs when the contract is executed */
47
+ function greeter(string _greeting) public {
48
+ greeting = _greeting;
49
+ }
50
+
51
+ /* Main function */
52
+ function greet() constant returns (string) {
53
+ return greeting;
54
+ }
55
+ }
56
+ EOS
57
+
58
+ templates["test_helper.rb"] = <<~'EOS'
59
+ require "ether_dev/test_helper"
60
+ EOS
61
+
62
+ templates["greeter_test.rb"] = <<~'EOS'
63
+ require "test_helper"
64
+
65
+ class GreeterTest < EtherDev::TestCase
66
+ def test_greet
67
+ @contract.deploy_and_wait("Hello, World!")
68
+
69
+ assert_equal "Hello, World!", @contract.call.greet()
70
+ end
71
+ end
72
+ EOS
73
+
74
+ templates
75
+ end
76
+ end
77
+ end
@@ -0,0 +1 @@
1
+ load "test_task.rake"
@@ -0,0 +1,34 @@
1
+ module EtherDev
2
+ class TestCase < ::Minitest::Test
3
+ def setup
4
+ @formatter = Ethereum::Formatter.new
5
+ contract_name = self.class.name.dup
6
+ contract_name.slice!("Test")
7
+
8
+ @config = YAML.load(File.open("config/blockchain.yml"))[ENV["BLOCKCHAIN_ENV"] || "test"] || {}
9
+ @client = Ethereum::HttpClient.create(@config["rpc"], true)
10
+
11
+ @contract = Ethereum::Contract.create(file: "contracts/#{contract_name}.sol", client: @client)
12
+ Eth.configure { |c| c.chain_id = @client.net_version["result"].to_i }
13
+
14
+ @default_key = nil
15
+ @default_account = nil
16
+
17
+ if private_key = @config["account_key"]
18
+ @default_key = Eth::Key.new priv: private_key
19
+ @default_account = @default_key.address
20
+ else
21
+ @default_account = @client.default_account
22
+ end
23
+
24
+ @contract.key = @default_key if @default_key.present?
25
+ @contract.sender = @default_account
26
+ end
27
+
28
+ protected
29
+
30
+ def signing_account?
31
+ @default_key.present?
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ require "minitest"
2
+ require "minitest/autorun"
3
+ require "ethereum.rb"
4
+ require "eth"
5
+ require "yaml"
6
+ require "ether_dev/test_case"
@@ -0,0 +1,8 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << %w(lib test)
5
+ t.test_files = FileList['test/**/*_test.rb']
6
+ end
7
+
8
+ task default: :test
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etherdev
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Michiel Sikkes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ethereum.rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.20.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.20.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.11'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.3'
83
+ description: A clean and simple development framework for Ethereum development and
84
+ deployment
85
+ email: michiel.sikkes@gmail.com
86
+ executables:
87
+ - etherdev
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - README.md
92
+ - bin/etherdev
93
+ - lib/ether_dev.rb
94
+ - lib/ether_dev/cli.rb
95
+ - lib/ether_dev/generators/project_generator.rb
96
+ - lib/ether_dev/generators/project_templates.rb
97
+ - lib/ether_dev/rake_tasks.rb
98
+ - lib/ether_dev/test_case.rb
99
+ - lib/ether_dev/test_helper.rb
100
+ - lib/ether_dev/test_task.rake
101
+ homepage: https://github.com/michiels/etherdev
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.6.11
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: A very simple development framework for Ethereum and Solidity smart contracts
125
+ test_files: []