Skip to content

Commit

Permalink
eth/solidity: enable --via-ir (#232)
Browse files Browse the repository at this point in the history
* eth/solidity: enable --via-ir

* spec: adjust tests
  • Loading branch information
q9f committed May 8, 2023
1 parent dcac24b commit 5013702
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/eth/solidity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def initialize(path = nil)
def compile(contract)
raise Errno::ENOENT, "Contract file not found: #{contract}" unless File.exist? contract
flag_opt = "--optimize"
flag_ir = "--via-ir"
flag_json = "--combined-json=bin,abi"
path = File.realpath contract
output, error, status = Open3.capture3 @compiler, flag_opt, flag_json, path
output, error, status = Open3.capture3 @compiler, flag_opt, flag_ir, flag_json, path
raise SystemCallError, "Unable to run solc compiler!" if status.exitstatus === 127
raise CompilerError, error unless status.success?
json = JSON.parse output
Expand Down
8 changes: 4 additions & 4 deletions spec/eth/solidity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
result = solc.compile contract
expect(result.keys).to eq ["Dummy"]
expect(result["Dummy"]["abi"]).to eq JSON.parse '[{"inputs":[],"name":"get","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"}]'
expect(result["Dummy"]["bin"]).to start_with "608060405234801561001057600080fd5b50"
expect(result["Dummy"]["bin"]).to start_with "608080604052"
end

it "compiles the greeter contract" do
Expand All @@ -24,8 +24,8 @@
expect(result.keys).to eq ["Greeter", "Mortal"]
expect(result["Mortal"]["abi"]).to eq JSON.parse '[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"kill","outputs":[],"stateMutability":"nonpayable","type":"function"}]'
expect(result["Greeter"]["abi"]).to eq JSON.parse '[{"inputs":[{"internalType":"string","name":"message","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"greet","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"kill","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"setGreeting","outputs":[],"stateMutability":"nonpayable","type": "function"}]'
expect(result["Mortal"]["bin"]).to start_with "6080604052348015600f57600080fd5b5060"
expect(result["Greeter"]["bin"]).to start_with "608060405234801561001057600080fd5b5060"
expect(result["Mortal"]["bin"]).to start_with "608080604052"
expect(result["Greeter"]["bin"]).to start_with "6080604052"
end

it "deploys an ethereum-consensus deposit contract" do
Expand All @@ -34,7 +34,7 @@
result = solc.compile contract
expect(result["DepositContract"]).to be
payload = result["DepositContract"]["bin"]
expect(payload).to start_with "60806040523480156200001157600080fd5b5060"
expect(payload).to start_with "604060808152"
params = {
from: geth.default_account,
priority_fee: 0,
Expand Down

0 comments on commit 5013702

Please sign in to comment.