Class: Remitmd::MockRemit
- Inherits:
-
Object
- Object
- Remitmd::MockRemit
- Defined in:
- lib/remitmd/mock.rb
Overview
In-memory test double for remit.md. Zero network, zero latency, deterministic.
MockRemit gives you a RemitWallet backed by in-memory state so you can test your agent's payment logic without a live API or spending real USDC.
Constant Summary collapse
- MOCK_ADDRESS =
"0xMockWallet0000000000000000000000000001"- DEFAULT_BALANCE =
BigDecimal("10000")
Instance Method Summary collapse
-
#balance ⇒ Object
Current mock balance.
-
#initialize(balance: DEFAULT_BALANCE) ⇒ MockRemit
constructor
A new instance of MockRemit.
-
#reset ⇒ Object
Reset all state.
-
#set_balance(amount) ⇒ Object
Override the simulated USDC balance.
-
#total_paid_to(recipient) ⇒ Object
Sum of all USDC sent to
recipient. -
#transaction_count ⇒ Object
Total number of transactions recorded.
-
#transactions ⇒ Object
All transactions recorded.
-
#wallet ⇒ Object
Return a RemitWallet backed by this mock.
-
#was_paid?(recipient, amount) ⇒ Boolean
True if a payment of exactly
amountUSDC was sent torecipient.
Constructor Details
#initialize(balance: DEFAULT_BALANCE) ⇒ MockRemit
Returns a new instance of MockRemit.
27 28 29 30 |
# File 'lib/remitmd/mock.rb', line 27 def initialize(balance: DEFAULT_BALANCE) @mutex = Mutex.new @state = initial_state(BigDecimal(balance.to_s)) end |
Instance Method Details
#balance ⇒ Object
Current mock balance.
48 49 50 |
# File 'lib/remitmd/mock.rb', line 48 def balance @mutex.synchronize { @state[:balance] } end |
#reset ⇒ Object
Reset all state. Call between test cases to prevent state leakage.
38 39 40 |
# File 'lib/remitmd/mock.rb', line 38 def reset @mutex.synchronize { @state.replace(initial_state(DEFAULT_BALANCE)) } end |
#set_balance(amount) ⇒ Object
Override the simulated USDC balance.
43 44 45 |
# File 'lib/remitmd/mock.rb', line 43 def set_balance(amount) @mutex.synchronize { @state[:balance] = BigDecimal(amount.to_s) } end |
#total_paid_to(recipient) ⇒ Object
Sum of all USDC sent to recipient.
73 74 75 76 77 78 79 |
# File 'lib/remitmd/mock.rb', line 73 def total_paid_to(recipient) @mutex.synchronize do @state[:transactions] .select { |tx| tx.to.casecmp(recipient).zero? } .sum(BigDecimal("0"), &:amount) end end |
#transaction_count ⇒ Object
Total number of transactions recorded.
58 59 60 |
# File 'lib/remitmd/mock.rb', line 58 def transaction_count @mutex.synchronize { @state[:transactions].length } end |
#transactions ⇒ Object
All transactions recorded.
53 54 55 |
# File 'lib/remitmd/mock.rb', line 53 def transactions @mutex.synchronize { @state[:transactions].dup } end |
#wallet ⇒ Object
Return a RemitWallet backed by this mock. No private key required.
33 34 35 |
# File 'lib/remitmd/mock.rb', line 33 def wallet RemitWallet.new(signer: MockSigner.new(MOCK_ADDRESS), transport: MockTransport.new(@state, @mutex)) end |
#was_paid?(recipient, amount) ⇒ Boolean
True if a payment of exactly amount USDC was sent to recipient.
63 64 65 66 67 68 69 70 |
# File 'lib/remitmd/mock.rb', line 63 def was_paid?(recipient, amount) d = BigDecimal(amount.to_s) @mutex.synchronize do @state[:transactions].any? do |tx| tx.to.casecmp(recipient).zero? && tx.amount == d end end end |