Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thesmartnik/rspec-eth
RSpec extension that allows to easily test solidity smart contracts
https://github.com/thesmartnik/rspec-eth
ethereum rspec solidity-contracts
Last synced: about 1 month ago
JSON representation
RSpec extension that allows to easily test solidity smart contracts
- Host: GitHub
- URL: https://github.com/thesmartnik/rspec-eth
- Owner: TheSmartnik
- License: mit
- Created: 2022-03-30T15:06:59.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-23T22:44:42.000Z (over 1 year ago)
- Last Synced: 2024-10-14T21:10:12.627Z (about 1 month ago)
- Topics: ethereum, rspec, solidity-contracts
- Language: Ruby
- Homepage:
- Size: 15.6 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RSpec::Eth
RSpec extension that allows to easily test solidity smart contracts.
## What it does
* Spins up ganache server for tests
* Adds a few handy methods to ease testing of solidity contracts in ruby main ones:
1. `contract` to access contract
2. `accounts` to access addresses used by ganacheIt's build on top of [etherium.rb](https://github.com/EthWorks/ethereum.rb). For documentation on how to interact with etherium blockchain please refer to its documentation
## Example Usage
Given a simple [Greeter contract](https://github.com/TheSmartnik/rspec-eth/blob/master/contracts/simple_greeter.sol). Here is an example of basic spec```ruby
RSpec.describe 'SimpleGreeter', type: :smart_contract do
before { contract.deploy_and_wait }it 'sets greeting' do
expect(contract.call.greet).to eq("Hello, World!")
endit 'changes message' do
contract.transact_and_wait.set_super_greeting("Yo")expect(contract.call.greet).to eq("Yo")
endcontext 'when sender not owner' do
before { contract.sender = accounts[1] }it 'trying to set not from owner' do
expect {
contract.transact_and_wait.set_super_greeting("Yo")
}.to raise_exception(IOError, "VM Exception while processing transaction: revert Only owner")
end
end
end
```## Installation
### Prerequisite
1. Install ganache-cli
```
npm install -g ganache-cli
```
2. [Install solidity compilier](https://docs.soliditylang.org/en/v0.8.9/installing-solidity.html)
```
brew install solidity
```3. Add gem to a Gemfile
Add this line to your application's Gemfile:```ruby
gem 'rspec-eth'
```4. Require extension in `spec_helper.rb` or `rails_helper.rb`
```
require 'rspec/eth'
```## Configuration
`RSpec::Eth` provides a few configuration option that you probably won't need
```ruby
# spec_helper.rbRSpec::Eth.configure do |config|
config.account_keys_path = temp_path # Path for accounts created
config.host = '127.0.0.1' # Host of ganache server
config.port = '8545' # Port of ganache server
config.contracts_path = 'contracts'# Set paths for your contracts
end```
## Development
After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rspec` to run the tests.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/TheSmartnik/rspec-eth.