Skip to content

Instantly share code, notes, and snippets.

View iamdefinitelyahuman's full-sized avatar
💭
Making breaking changes

iamdefinitelyahuman

💭
Making breaking changes
  • Earth
View GitHub Profile
{
"0x0000000484f2217f1a64eb6d24b5cee446faeae5": 68.69048107855006,
"0x000006eee6e39015cb523aebdd4d0b1855aba682": 224.9197902100917,
"0x0000a441fbb1fbaadf246539bf253a42abd31494": 708.9370225453673,
"0x0004d2a2f9a823c1a585fde6514a17ff695e0001": 17266.765333736228,
"0x0006e4548aed4502ec8c844567840ce6ef1013f5": 175.35113630869478,
"0x000b75fcdc15d41277deb033c72d2c8d774ccced": 2.0369790054406494,
"0x000d7321f6767c3910bbce248cb9df5c8eb0edf9": 14.229752092760547,
"0x0037f3deb586d1b34abaae92341f9bb70527a4d4": 940.0786947880968,
"0x0053b5daa6d4c2e3d16f2b9c10dc04e92b14a818": 0.2089564825243452,
def test_mine_blocks(accounts, chain):
tx = accounts[0].transfer(accounts[1], "1 ether")
# mine 100 blocks
chain.mine(100)
assert chain[-1].number == tx.block_number + 100
@external
def withdraw_from(_value: uint256) -> bool:
assert self.deposited[msg.sender] >= _value, "Insufficient balance"
self.deposited[msg.sender] = _value
send(msg.sender, _value)
return True
import brownie
from brownie.test import strategy
class StateMachine:
value = strategy('uint256', max_value="1 ether")
address = strategy('address')
def __init__(cls, accounts, Depositer):
# deploy the contract at the start of the test
deposited: public(HashMap[address, uint256])
@external
@payable
def deposit_for(_receiver: address) -> bool:
self.deposited[_receiver] += msg.value
return True
@external
from brownie import accounts
from brownie.test import given, strategy
@given(
receiver=strategy('address', exclude=accounts[0]),
amount=strategy('uint256', max_value=10**18),
)
def test_transfer_adjusts_receiver_balance(accounts, token, receiver, amount):
balance = token.balanceOf(receiver)
token.transfer(to, amount, {'from': accounts[0]})
from brownie.test import given, strategy
@given(amount=strategy('uint256', max_value=10**18))
def test_transfer_adjusts_receiver_balance(accounts, token, amount):
balance = token.balanceOf(accounts[1])
token.transfer(accounts[1], amount, {'from': accounts[0]})
assert token.balanceOf(accounts[1]) == balance + amount
def test_transfer_adjusts_receiver_balance(accounts, token):
balance = token.balanceOf(accounts[1])
token.transfer(accounts[1], 10**18, {'from': accounts[0]})
assert token.balanceOf(accounts[1]) == balance + 10**18
def test_insufficient_balance(token, accounts):
balance = token.balanceOf(accounts[1])
with brownie.reverts("dev: Insufficient balance"):
token.adminTransfer(accounts[1], accounts[2], balance + 100)
function adminTransfer(
address _from,
address _to,
uint256 _amount
)
external
returns (bool)
{
require(msg.sender == owner); // dev: Only callable by owner
require(permitted[_to]); // dev: Receiver is not permitted