-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Claude 3.5 Sonnet
- Loading branch information
Showing
7 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This is free and unencumbered software released into the public domain. | ||
|
||
require 'near' | ||
|
||
RSpec.describe NEAR::Account do | ||
describe '#initialize' do | ||
it 'instantiates an account with the given ID' do | ||
account = NEAR::Account.new('alice.near') | ||
expect(account.id).to eq('alice.near') | ||
end | ||
|
||
it 'converts the input to a string' do | ||
account = NEAR::Account.new(:'alice.near') | ||
expect(account.id).to eq('alice.near') | ||
end | ||
end | ||
|
||
describe '#inspect' do | ||
it 'returns the account ID as a Ⓝ-prefixed string' do | ||
account = NEAR::Account.new('alice.near') | ||
expect(account.inspect).to eq('Ⓝalice.near') | ||
end | ||
end | ||
|
||
describe '#to_s' do | ||
it 'returns the account ID as a string' do | ||
account = NEAR::Account.new('alice.near') | ||
expect(account.to_s).to eq('alice.near') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# This is free and unencumbered software released into the public domain. | ||
|
||
require 'near' | ||
|
||
RSpec.describe NEAR::Balance do | ||
describe '#initialize' do | ||
context 'with valid input' do | ||
it 'accepts an integer' do | ||
balance = NEAR::Balance.new(100) | ||
expect(balance.to_i).to eq(100) | ||
end | ||
|
||
it 'accepts a float' do | ||
balance = NEAR::Balance.new(100.5) | ||
expect(balance.to_f).to eq(100.5) | ||
end | ||
|
||
it 'accepts a rational' do | ||
balance = NEAR::Balance.new(Rational(201, 2)) | ||
expect(balance.to_r).to eq(Rational(201, 2)) | ||
end | ||
|
||
it 'accepts a decimal' do | ||
balance = NEAR::Balance.new(BigDecimal('123.45')) | ||
expect(balance.to_f).to eq(123.45) | ||
end | ||
|
||
it 'accepts a string' do | ||
balance = NEAR::Balance.new('123.45') | ||
expect(balance.to_f).to eq(123.45) | ||
end | ||
end | ||
|
||
context 'with invalid input' do | ||
it 'raises ArgumentError for invalid strings' do | ||
expect { NEAR::Balance.new('invalid') }.to raise_error(ArgumentError) | ||
end | ||
|
||
it 'raises ArgumentError for nil' do | ||
expect { NEAR::Balance.new(nil) }.to raise_error(ArgumentError) | ||
end | ||
end | ||
end | ||
|
||
describe '#inspect' do | ||
it 'returns the balance as a Ⓝ-prefixed string' do | ||
balance = NEAR::Balance.new(100.5) | ||
expect(balance.inspect).to eq('Ⓝ100.5') | ||
end | ||
end | ||
|
||
describe '#to_s' do | ||
it 'returns the balance as a string' do | ||
balance = NEAR::Balance.new(100.5) | ||
expect(balance.to_s).to eq('100.5') | ||
end | ||
end | ||
|
||
describe '#to_r' do | ||
it 'returns the balance as a rational' do | ||
balance = NEAR::Balance.new(Rational(201, 2)) | ||
expect(balance.to_r).to eq(Rational(201, 2)) | ||
end | ||
end | ||
|
||
describe '#to_i' do | ||
it 'returns the balance as an integer' do | ||
balance = NEAR::Balance.new(100.5) | ||
expect(balance.to_i).to eq(100) | ||
end | ||
end | ||
|
||
describe '#to_f' do | ||
it 'returns the balance as a float' do | ||
balance = NEAR::Balance.new(100) | ||
expect(balance.to_f).to eq(100.0) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# This is free and unencumbered software released into the public domain. | ||
|
||
require 'near' | ||
|
||
RSpec.describe NEAR::Block do | ||
describe '.now' do | ||
it 'instantiates a block representing the current state' do | ||
block = NEAR::Block.now | ||
expect(block.height).to be_nil | ||
expect(block.hash).to be_nil | ||
end | ||
end | ||
|
||
describe '.at_height' do | ||
it 'instantiates a block for a specific height' do | ||
block = NEAR::Block.at_height(185_299_288) | ||
expect(block.height).to eq(185_299_288) | ||
expect(block.hash).to be_nil | ||
end | ||
|
||
it 'converts the height to an integer' do | ||
block = NEAR::Block.at_height('185299288') | ||
expect(block.height).to eq(185_299_288) | ||
end | ||
end | ||
|
||
describe '.at_hash' do | ||
it 'instantiates a block for a specific hash' do | ||
block = NEAR::Block.at_hash('8Y5HyGLa5oX42bWm21neXTNLTQrE4yhGMWs4GLhTywzk') | ||
expect(block.hash).to eq('8Y5HyGLa5oX42bWm21neXTNLTQrE4yhGMWs4GLhTywzk') | ||
expect(block.height).to be_nil | ||
end | ||
|
||
it 'converts the hash to a string' do | ||
block = NEAR::Block.at_hash(:'8Y5HyGLa5oX42bWm21neXTNLTQrE4yhGMWs4GLhTywzk') | ||
expect(block.hash).to eq('8Y5HyGLa5oX42bWm21neXTNLTQrE4yhGMWs4GLhTywzk') | ||
end | ||
end | ||
|
||
describe '#to_cli_args' do | ||
it 'returns ["now"] for the current block' do | ||
block = NEAR::Block.now | ||
expect(block.to_cli_args).to eq(['now']) | ||
end | ||
|
||
it 'returns height arguments for height-based blocks' do | ||
block = NEAR::Block.at_height(185_299_288) | ||
expect(block.to_cli_args).to eq(['at-block-height', 185_299_288]) | ||
end | ||
|
||
it 'returns hash arguments for hash-based blocks' do | ||
block = NEAR::Block.at_hash('8Y5HyGLa5oX42bWm21neXTNLTQrE4yhGMWs4GLhTywzk') | ||
expect(block.to_cli_args).to eq(['at-block-hash', '8Y5HyGLa5oX42bWm21neXTNLTQrE4yhGMWs4GLhTywzk']) | ||
end | ||
end | ||
|
||
describe '#to_s' do | ||
it 'returns "now" for the current block' do | ||
block = NEAR::Block.now | ||
expect(block.to_s).to eq('now') | ||
end | ||
|
||
it 'returns the height for height-based blocks' do | ||
block = NEAR::Block.at_height(185_299_288) | ||
expect(block.to_s).to eq('185299288') | ||
end | ||
|
||
it 'returns the hash for hash-based blocks' do | ||
block = NEAR::Block.at_hash('8Y5HyGLa5oX42bWm21neXTNLTQrE4yhGMWs4GLhTywzk') | ||
expect(block.to_s).to eq('8Y5HyGLa5oX42bWm21neXTNLTQrE4yhGMWs4GLhTywzk') | ||
end | ||
end | ||
end |