Example #1
0
def test_payment_splitter_odd(chain, payment_splitter, team_multisig, customer,
                              customer_2):
    """ Testing basic splitting """
    w3 = chain.web3

    customer_initial_balance = w3.eth.getBalance(customer)
    customer_2_initial_balance = w3.eth.getBalance(customer_2)

    check_gas(
        chain,
        w3.eth.sendTransaction({
            "value": 1,
            "from": team_multisig,
            "to": payment_splitter.address,
            "gas": 23000
        }))
    assert w3.eth.getBalance(payment_splitter.address) == 1
    assert w3.eth.getBalance(customer) == customer_initial_balance
    assert w3.eth.getBalance(customer_2) == customer_2_initial_balance
    check_gas(chain,
              payment_splitter.transact({
                  "from": team_multisig
              }).split())

    assert w3.eth.getBalance(payment_splitter.address) == 1
    assert w3.eth.getBalance(customer) == customer_initial_balance
    assert w3.eth.getBalance(customer_2) == customer_2_initial_balance
Example #2
0
def test_security_token_approve_bad_amount(chain, security_token, security_token_initial_supply, team_multisig, zero_address, customer):
    check_gas(chain, security_token.transact({"from": team_multisig}).approve(customer, security_token_initial_supply))
    assert security_token.call().allowance(team_multisig, customer) == security_token_initial_supply
    with pytest.raises(TransactionFailed):
        security_token.transact({"from": customer}).transferFrom(team_multisig, customer, (security_token_initial_supply * 2))
    assert security_token.call().balanceOf(team_multisig) == security_token_initial_supply
    assert security_token.call().balanceOf(customer) == 0
def test_advanced_transfer_agent_whiteblacklisted(chain, security_token,
                                                  advanced_transfer_agent,
                                                  team_multisig, customer,
                                                  basic_kyc):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 10))
    assert security_token.call().balanceOf(customer) == 10

    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).setTransactionVerifier(advanced_transfer_agent.address))
    check_gas(
        chain,
        advanced_transfer_agent.transact({
            "from": team_multisig
        }).setWhitelist(team_multisig, True))
    check_gas(
        chain,
        advanced_transfer_agent.transact({
            "from": team_multisig
        }).setBlacklist(team_multisig, True))

    with pytest.raises(TransactionFailed):
        check_gas(
            chain,
            security_token.transact({
                "from": customer
            }).transfer(team_multisig, 10))

    assert security_token.call().balanceOf(customer) == 10
def test_restricted_transfer_agent_whitelisted(chain, security_token,
                                               restricted_transfer_agent,
                                               team_multisig, customer,
                                               basic_kyc):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 10))
    assert security_token.call().balanceOf(customer) == 10

    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).setTransactionVerifier(restricted_transfer_agent.address))
    check_gas(
        chain,
        basic_kyc.transact({
            "from": team_multisig
        }).setAttributes(team_multisig, 1))
    check_gas(
        chain,
        basic_kyc.transact({
            "from": team_multisig
        }).setAttributes(customer, 1))

    check_gas(
        chain,
        security_token.transact({
            "from": customer
        }).transfer(team_multisig, 10))

    assert security_token.call().balanceOf(customer) == 0
Example #5
0
def payout_contract(chain, team_multisig, mock_kyc, security_token, test_token, security_token_verifier) -> Contract:
    """Create the Voting Contract."""

    # CheckpointToken _token, MockKYC _KYC, bytes32 name, bytes32 URI, uint256 _type, uint256 _hash, bytes32[] _options
    # address, address, address, bytes32, bytes32, uint256, uint256, bytes32[]
    args = [
        security_token.address,
        test_token.address,
        mock_kyc.address,
        to_bytes(text="Pay X"),
        to_bytes(text="http://tokenmarket.net"),
        123,
        0,
        [to_bytes(text="Vested for dividend")]
    ]

    tx = {
        "from": team_multisig
    }

    contract, hash_ = chain.provider.deploy_contract('PayoutContract', deploy_args=args, deploy_transaction=tx)

    check_gas(chain, hash_)

    return contract
Example #6
0
def test_payment_splitter_multiparty(chain, payment_splitter_multiparty,
                                     team_multisig, malicious_address,
                                     customer, customer_2):
    """ Testing multiparty splitting """
    w3 = chain.web3

    customer_initial_balance = w3.eth.getBalance(customer)
    customer_2_initial_balance = w3.eth.getBalance(customer_2)
    malicious_address_initial_balance = w3.eth.getBalance(malicious_address)

    check_gas(
        chain,
        w3.eth.sendTransaction({
            "value": 100,
            "from": team_multisig,
            "to": payment_splitter_multiparty.address,
            "gas": 23000
        }))

    assert w3.eth.getBalance(payment_splitter_multiparty.address) == 100
    assert w3.eth.getBalance(
        malicious_address) == malicious_address_initial_balance
    assert w3.eth.getBalance(customer) == customer_initial_balance
    assert w3.eth.getBalance(customer_2) == customer_2_initial_balance
    check_gas(
        chain,
        payment_splitter_multiparty.transact({
            "from": team_multisig
        }).split())

    assert w3.eth.getBalance(payment_splitter_multiparty.address) == 1
    assert w3.eth.getBalance(
        malicious_address) == malicious_address_initial_balance + 33
    assert w3.eth.getBalance(customer) == customer_initial_balance + 33
    assert w3.eth.getBalance(customer_2) == customer_2_initial_balance + 33
Example #7
0
def test_security_token_transfer(chain, security_token, team_multisig, zero_address, customer):
    """Basic ERC-20 Transfer"""

    # https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC20.sol

    check_gas(chain, security_token.transact({"from": team_multisig}).transfer(customer, 100), gaslimit=140000)
    assert security_token.call().balanceOf(customer) == 100
    assert security_token.call().balanceOf(zero_address) == 0
    assert security_token.call().balanceAt(customer, 1) == 0
    assert security_token.call().balanceAt(customer, 999999) == 100
def test_security_token_issue(chain, security_token,
                              security_token_initial_supply, team_multisig,
                              zero_address, customer):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).issueTokens(security_token_initial_supply))
    assert security_token.call().totalSupply() == (
        security_token_initial_supply * 2)
def test_security_token_change_name_and_symbol(chain, security_token,
                                               security_token_initial_supply,
                                               team_multisig, zero_address,
                                               customer):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).setTokenInformation("NewToken", "NEW"))
    assert security_token.call().name() == "NewToken"
    assert security_token.call().symbol() == "NEW"
def basic_kyc(chain, team_multisig) -> Contract:
    """Create the transaction verifier contract."""

    tx = {"from": team_multisig}

    contract, hash_ = chain.provider.deploy_contract('BasicKYC',
                                                     deploy_transaction=tx)

    check_gas(chain, hash_)

    return contract
def security_token_verifier(chain, team_multisig) -> Contract:
    """Create the transaction verifier contract."""

    tx = {"from": team_multisig}

    contract, hash_ = chain.provider.deploy_contract(
        'MockSecurityTransferAgent', deploy_transaction=tx)

    check_gas(chain, hash_)

    return contract
def restricted_transfer_agent(chain, team_multisig, mock_kyc) -> Contract:
    """Create the transaction verifier contract."""
    args = [mock_kyc.address]

    tx = {
        "from": team_multisig
    }

    contract, hash_ = chain.provider.deploy_contract('RestrictedTransferAgent', deploy_args=args, deploy_transaction=tx)

    check_gas(chain, hash_)

    return contract
def test_security_token_burn(chain, security_token,
                             security_token_initial_supply, team_multisig,
                             zero_address, customer):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(security_token.address, security_token_initial_supply))
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).burnTokens(security_token_initial_supply - 1))
    assert security_token.call().totalSupply() == 1
Example #14
0
def test_erc865(chain, security_token, team_multisig, customer, private_key, signer_address):
    check_gas(chain, security_token.transact({"from": team_multisig}).transfer(signer_address, 1234))

    token_addr = int(security_token.address, 16).to_bytes(20, byteorder="big")
    to_addr = int(team_multisig, 16).to_bytes(20, byteorder="big")
    value = int(123).to_bytes(32, byteorder="big")
    fee = int(123).to_bytes(32, byteorder="big")
    nonce = int(123).to_bytes(32, byteorder="big")
    prefix = int(0x48664c16).to_bytes(4, byteorder="big")
    payload = prefix + token_addr + to_addr + value + fee + nonce
    signed_data = sign(payload, private_key, hash_function=keccak)
    key_raw = signed_data["r_bytes"] + signed_data["s_bytes"] + signed_data["v"].to_bytes(1, byteorder="big")

    security_token.transact({"from": customer}).transferPreSigned(key_raw, team_multisig, 123, 123, 123)
def test_security_token_freeze(chain, security_token, security_token_verifier,
                               team_multisig, customer):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 10))
    assert security_token.call().balanceOf(customer) == 10

    check_gas(
        chain,
        security_token_verifier.transact({
            "from": team_multisig
        }).freeze())
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).setTransactionVerifier(security_token_verifier.address))

    with pytest.raises(TransactionFailed):
        check_gas(
            chain,
            security_token.transact({
                "from": customer
            }).transfer(team_multisig, 10))

    assert security_token.call().balanceOf(customer) == 10
def test_security_token_force(chain, security_token,
                              security_token_initial_supply, team_multisig,
                              zero_address, customer):
    assert security_token.call().balanceOf(
        team_multisig) == security_token_initial_supply
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).forceTransfer(team_multisig, customer,
                         security_token_initial_supply))
    assert security_token.call().totalSupply() == security_token_initial_supply
    assert security_token.call().balanceOf(team_multisig) == 0
    assert security_token.call().balanceOf(
        customer) == security_token_initial_supply
Example #17
0
def test_payment_splitter_zero(chain, payment_splitter, team_multisig,
                               customer, customer_2):
    """ Testing basic splitting """
    w3 = chain.web3

    customer_initial_balance = w3.eth.getBalance(customer)
    customer_2_initial_balance = w3.eth.getBalance(customer_2)

    assert w3.eth.getBalance(payment_splitter.address) == 0
    check_gas(chain,
              payment_splitter.transact({
                  "from": team_multisig
              }).split())

    assert w3.eth.getBalance(payment_splitter.address) == 0
    assert w3.eth.getBalance(customer) == customer_initial_balance
    assert w3.eth.getBalance(customer_2) == customer_2_initial_balance
def test_security_token_ask_balanceat(chain, security_token, security_token_initial_supply, team_multisig, customer):
    initial_balance = security_token.call().balanceOf(team_multisig)
    check_gas(chain, security_token.transact({"from": team_multisig}).checkpoint())
    check_gas(chain, security_token.transact({"from": team_multisig}).transfer(security_token.address, security_token_initial_supply))
    check_gas(chain, security_token.transact({"from": team_multisig}).checkpoint())
    check_gas(chain, security_token.transact().balanceAt(team_multisig, 1), gaslimit=26500)

    historical_balance = security_token.call().balanceAt(team_multisig, 0)
    current_balance = security_token.call().balanceAt(team_multisig, 222)
    assert historical_balance == initial_balance
    assert security_token.call().balanceAt(team_multisig, 1) == security_token.call().balanceAt(team_multisig, 2)
Example #19
0
def announcement(chain, team_multisig, announcement_name, announcement_uri, announcement_type, announcement_hash) -> Contract:
    """Create a bogus announcement for testing"""

    args = [to_bytes(text=announcement_name), to_bytes(text=announcement_uri), announcement_type, announcement_hash]

    tx = {
        "from": team_multisig
    }

    contract, hash_ = chain.provider.deploy_contract('BogusAnnouncement', deploy_args=args, deploy_transaction=tx)


    check_gas(chain, hash_)

    assert removeNonPrintable(contract.call().announcementName()) == announcement_name
    assert removeNonPrintable(contract.call().announcementURI()) == announcement_uri
    assert contract.call().announcementType() == announcement_type

    return contract
def test_security_token_approve(chain, security_token,
                                security_token_initial_supply, team_multisig,
                                zero_address, customer):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).approve(customer, security_token_initial_supply))
    assert security_token.call().allowance(
        team_multisig, customer) == security_token_initial_supply
    check_gas(
        chain,
        security_token.transact({
            "from": customer
        }).transferFrom(team_multisig, customer,
                        security_token_initial_supply))
    assert security_token.call().balanceOf(team_multisig) == 0
    assert security_token.call().balanceOf(
        customer) == security_token_initial_supply
Example #21
0
def security_token(monkey_patch_py_evm_gas_limit, chain, team_multisig, security_token_name, security_token_symbol, security_token_url, security_token_initial_supply) -> Contract:
    """Create the token contract."""

    args = [security_token_name, security_token_symbol, security_token_url]  # Owner set

    tx = {
        "from": team_multisig,
        "gas": 9999999,
    }

    contract, hash_ = chain.provider.deploy_contract('SecurityToken', deploy_args=args, deploy_transaction=tx)

    check_gas(chain, hash_)

    check_gas(chain, contract.transact(tx).issueTokens(security_token_initial_supply))

    assert contract.call().totalSupply() == security_token_initial_supply
    assert contract.call().url() == security_token_url
    assert contract.call().balanceOf(team_multisig) == security_token_initial_supply

    return contract
def security_token(chain, team_multisig, security_token_name,
                   security_token_symbol,
                   security_token_initial_supply) -> Contract:
    """Create the token contract."""

    args = [security_token_name, security_token_symbol]  # Owner set

    tx = {"from": team_multisig}

    contract, hash_ = chain.provider.deploy_contract('SecurityToken',
                                                     deploy_args=args,
                                                     deploy_transaction=tx)

    check_gas(chain, hash_)

    check_gas(chain,
              contract.transact(tx).addAddressToWhitelist(team_multisig))
    check_gas(chain,
              contract.transact(tx).issueTokens(security_token_initial_supply))

    assert contract.call().totalSupply() == security_token_initial_supply
    assert contract.call().balanceOf(
        team_multisig) == security_token_initial_supply

    return contract
def test_security_token_transfer_stresstest(chain, security_token,
                                            team_multisig, zero_address,
                                            customer):
    """Basic ERC-20 Transfer"""

    # Feel free to raise the number of iterations according to your needs:
    # (These were run with fixed y = 1)
    # After 3 iterations, balanceAt() takes      25,177 gas each
    # After 3,000 iterations, balanceAt() takes  37,224 gas each
    # After 10,000 iterations, balanceAt() takes 39,780 gas each
    # Randomized 3,000 iterations (current) took 37,284 gas per transaction
    for x in range(3):
        check_gas(
            chain,
            security_token.transact({
                "from": team_multisig
            }).transfer(customer, 100))
        assert security_token.call().balanceOf(customer) == 100
        assert security_token.call().balanceOf(zero_address) == 0
        check_gas(
            chain,
            security_token.transact({
                "from": customer
            }).transfer(team_multisig, 100))
        y = 1 + randint(0, x)
        check_gas(chain,
                  security_token.transact().balanceAt(customer, y),
                  tag=str(y))
        assert security_token.call().balanceOf(customer) == 0
def mock_kyc(chain, team_multisig, customer) -> Contract:
    """Create the Mock KYC contract."""

    tx = {
        "from": team_multisig
    }

    contract, hash_ = chain.provider.deploy_contract('BasicKYC', deploy_transaction=tx)

    check_gas(chain, hash_)

    check_gas(chain, contract.transact(tx).adminAddRole(team_multisig, "setter"))
    check_gas(chain, contract.transact(tx).setAttributes(customer, 1))
    check_gas(chain, contract.transact(tx).setAttributes(team_multisig, 1))


    return contract
Example #25
0
def test_payout_contract(chain, payout_contract, security_token, test_token, team_multisig, customer):
    start_balance = test_token.call().balanceOf(team_multisig)
    assert start_balance > 0
    check_gas(chain, test_token.transact({"from": team_multisig}).approve(payout_contract.address, start_balance))
    check_gas(chain, payout_contract.transact({"from": customer}).fetchTokens())

    initial_balance = test_token.call().balanceOf(team_multisig)
    check_gas(chain, payout_contract.transact({"from": team_multisig}).act(123))
    assert test_token.call().balanceOf(team_multisig) > initial_balance

    return
def test_security_token_failsafe(chain, security_token, failsafetester,
                                 team_multisig, customer):
    """Basic ERC-20 Transfer"""
    index = 2

    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 1))
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 1))
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 1))
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 1))

    original_block, original_balance = security_token.call().tokenBalances(
        customer, index)

    tester_result, tester_balance, tester_block = failsafetester.call(
    ).getTokenBalance(security_token.address, original_block, customer, index)

    assert tester_result == True
    assert tester_balance == original_balance
    assert tester_block == original_block

    tester_result, tester_balance, tester_block = failsafetester.call(
    ).getTokenBalance(security_token.address, original_block, customer, 0)
    assert tester_result == False

    with pytest.raises(TransactionFailed):
        failsafetester.call().getTokenBalance(security_token.address,
                                              original_block, customer, 9999)
def test_payout_contract(chain, payout_contract, security_token, test_token, team_multisig, customer):
    start_balance = test_token.call().balanceOf(team_multisig)
    assert start_balance > 0
    check_gas(chain, test_token.transact({"from": team_multisig}).approve(payout_contract.address, start_balance))
    check_gas(chain, payout_contract.transact({"from": customer}).fetchTokens())
    # check if tokens have been fetched
    assert test_token.functions.balanceOf(payout_contract.address).call() == start_balance

    # check tranfers
    initial_balance = test_token.call().balanceOf(team_multisig)
    check_gas(chain, payout_contract.transact({"from": team_multisig}).act(123))
    assert test_token.call().balanceOf(team_multisig) > initial_balance
    # check balance in payout contract
    # 0x0000000000000000000000000000000000000064 is default address(100)
    assert payout_contract.functions.balanceOf('0x0000000000000000000000000000000000000064').call()
    return
Example #28
0
def mock_kyc(chain, team_multisig, customer) -> Contract:
    """Create the Mock KYC contract."""

    tx = {
        "from": team_multisig
    }

    contract, hash_ = chain.provider.deploy_contract('BasicKYC', deploy_transaction=tx)

    check_gas(chain, hash_)

    check_gas(chain, contract.transact(tx).whitelistUser(customer, True))
    check_gas(chain, contract.transact(tx).whitelistUser(team_multisig, True))


    return contract
def test_security_token_transaction_verifier(chain, security_token,
                                             mock_security_transfer_agent,
                                             team_multisig, customer):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 10))
    assert security_token.call().balanceOf(customer) == 10

    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).setTransactionVerifier(mock_security_transfer_agent.address))

    check_gas(
        chain,
        security_token.transact({
            "from": customer
        }).transfer(team_multisig, 10))
    assert security_token.call().balanceOf(customer) == 9
def test_restricted_transfer_agent_not_listed(chain, security_token,
                                              restricted_transfer_agent,
                                              team_multisig, customer):
    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).transfer(customer, 10))
    assert security_token.call().balanceOf(customer) == 10

    check_gas(
        chain,
        security_token.transact({
            "from": team_multisig
        }).setTransactionVerifier(restricted_transfer_agent.address))

    with pytest.raises(TransactionFailed):
        check_gas(
            chain,
            security_token.transact({
                "from": customer
            }).transfer(team_multisig, 10))

    assert security_token.call().balanceOf(customer) == 10