Пример #1
0
 def buy_with_customer_id(self, buyer):
     tx_receipt = super().buy_with_customer_id(buyer.customerId,
                                               buyer.address,
                                               self.investment)
     if self.halted:
         fails("Buying using buyOnBehalfWithCustomerId fails if halted",
               tx_receipt)
     elif buyer.customerId == 0:
         fails(
             "Buying using buyOnBehalfWithCustomerId fails with invalid customer ID",
             tx_receipt)
     elif (self.states["PreFunding"] == self.state
           and not buyer.whitelisted):
         fails(
             "Buying using buyOnBehalfWithCustomerId fails if in PreFunding state and buyer isn't whitelisted",
             tx_receipt)
     elif (self.states["PreFunding"] != self.state
           and self.states["Funding"] != self.state):
         fails(
             "Buying using buyOnBehalfWithCustomerId fails if not in PreFunding nor Funding state",
             tx_receipt)
     else:
         succeeds("Buying using buyOnBehalfWithCustomerId succeeds",
                  tx_receipt)
         (wei_amount, token_amount) = self.calculate_token_amount(
             self.investment * (10**18), buyer.address)
         self.multisig_wei += wei_amount
         print(self.multisig_wei)
         print(self.web3.eth.getBalance(super().multisig_wallet()))
         self.token_balances[buyer.address] += token_amount
         self.tokens_sold_var += token_amount
Пример #2
0
 def set_early_participant_whitelist(self):
     succeeds(
         "Whitelist Account 1",
         super().set_early_participant_whitelist(self.accounts[1], True))
     succeeds(
         "Whitelist Account 2",
         super().set_early_participant_whitelist(self.accounts[2], True))
Пример #3
0
 def send_ether(self, buyer):
     tx_receipt = super().send_ether_to_crowdsale(buyer.address,
                                                  self.investment)
     if self.halted:
         fails("Sending ether to crowdsale fails if halted", tx_receipt)
     elif self.requiredCustomerId:
         fails("Sending ether to crowdsale fails with requiredCustomerId",
               tx_receipt)
     elif (self.states["PreFunding"] == self.state
           and not buyer.whitelisted):
         fails(
             "Sending ether to crowdsale fails if in PreFunding state and buyer isn't whitelisted",
             tx_receipt)
     elif (self.states["PreFunding"] != self.state
           and self.states["Funding"] != self.state):
         fails(
             "Sending ether to crowdsale fails if not in PreFunding nor Funding state",
             tx_receipt)
     else:
         succeeds("Sending ether to crowdsale succeeds", tx_receipt)
         (wei_amount, token_amount) = self.calculate_token_amount(
             self.investment * (10**18), buyer.address)
         self.multisig_wei += wei_amount
         print(self.multisig_wei)
         print(self.web3.eth.getBalance(super().multisig_wallet()))
         self.token_balances[buyer.address] += token_amount
         self.tokens_sold_var += token_amount
Пример #4
0
 def try_set_minimum_buy_value(self, new_minimum):
     if (self.state == self.states["PreFunding"]
             or self.state == self.states["Funding"]):
         succeeds("Set minimum buy value succeeds",
                  super().set_minimum_buy_value(new_minimum))
         self.minimum_buy_value = new_minimum
     else:
         fails("Set minimum buy value fails",
               super().set_minimum_buy_value(new_minimum))
Пример #5
0
 def try_update_price_agent(self, new_price_agent):
     if (self.state == self.states["PreFunding"]
             or self.state == self.states["Funding"]):
         succeeds("Update price agent succeeds",
                  super().update_price_agent(new_price_agent))
         self.priceAgent = new_price_agent
     else:
         fails("Update price agent fails",
               super().update_price_agent(new_price_agent))
Пример #6
0
 def try_update_eurs_per_eth(self, milieurs_amount, price_agent):
     if (self.state == self.states["PreFunding"] or self.state
             == self.states["Funding"]) and self.priceAgent == price_agent:
         succeeds("Update eurs per eth succeeds",
                  super().update_eurs_per_eth(milieurs_amount))
         self.milieurs_per_eth = milieurs_amount
     else:
         fails("Update eurs per eth fails",
               super().update_eurs_per_eth(milieurs_amount))
Пример #7
0
 def try_set_starting_time(self, starting_time):
     if self.state == self.states["PreFunding"] and int(round(time.time(
     ))) < starting_time and starting_time < super().ends_at():
         succeeds("Set starting time succeeds",
                  super().set_starting_time(starting_time))
         self.startsAt = starting_time
     else:
         fails("Set starting time fails",
               super().set_starting_time(starting_time))
Пример #8
0
 def try_set_ending_time(self, ending_time):
     if (self.state == self.states["PreFunding"] or self.state
             == self.states["Funding"]) and int(round(time.time(
             ))) < ending_time and super().starts_at() < ending_time:
         succeeds("Set starting time succeeds",
                  super().set_ending_time(ending_time))
         self.endsAt = ending_time
     else:
         fails("Set starting time fails",
               super().set_ending_time(ending_time))
Пример #9
0
 def try_finalize(self):
     if self.state == self.states["Success"] and not self.halted:
         succeeds("Finalization of Crowdsale succeeds", super().finalize())
         self.state = self.states["Finalized"]
         sold = self.tokens_sold_var + self.bounties_tokens
         to_share = (sold * 18) // 82
         self.multisig_tokens += to_share
         print(self.multisig_tokens)
         print(self.token_balance(self.multisig_wallet()))
         self.check_all_end_balances()
     else:
         fails("Finalization of Crowdsale fails", super().finalize())
Пример #10
0
 def try_preallocate(self):
     for investor in self.investors:
         tx_receipt = super().preallocate(investor.address,
                                          self.tokens_to_preallocate,
                                          self.wei_price_of_preallocation)
         if self.state == self.states[
                 "PreFunding"] or self.state == self.states["Funding"]:
             succeeds("Preallocate succeeds", tx_receipt)
             token_amount = self.tokens_to_preallocate * (10**18)
             self.token_balances[investor.address] += token_amount
             self.tokens_sold_var += token_amount
         else:
             fails("Preallocate fails", tx_receipt)
Пример #11
0
 def try_configuration_crowdsale(self):
     if self.state == self.states["PendingConfiguration"]:
         succeeds("Configuration of Crowdsale succeeds",
                  super().configuration_crowdsale())
         self.state = self.states["PreFunding"]
         self.startsAt = super().starts_at()
         self.endsAt = super().ends_at()
         self.bounties_tokens = self.multisig_tokens = super(
         ).initial_bounties_tokens()
         self.token = self.instantiate_token()
         print(self.multisig_tokens)
         print(self.token_balance(self.multisig_wallet()))
         assert self.token_balance(
             super().multisig_wallet()) == 252 * (10**5) * (10**18)
         assert self.token_balance(
             self.contract.address) == 1008 * (10**6) * (10**18)
         assert self.token_balance(
             super().multisig_wallet()) == self.params["multisig_supply"]
         assert self.token_balance(
             self.contract.address) == self.params["crowdsale_supply"]
     else:
         fails("Configuration of Crowdsale fails",
               super().configuration_crowdsale())
     print("ETA for ICO: " + str(super().eta_ico() + 1) + " seconds.")
Пример #12
0
 def unhalt(self):
     succeeds("Unhalt Crowdsale", super().unhalt())
     self.halted = False
Пример #13
0
 def halt(self):
     succeeds("Halt Crowdsale", super().halt())
     self.halted = True
Пример #14
0
 def require_signed_address(self, signer):
     succeeds("Unrequire Signed Address",
              super().set_require_signed_address(False, signer))
     self.signer = signer
     self.requiredSignedAddress = False
Пример #15
0

def get_minting_finished():
  return functions.mintingFinished().call()
def get_mint_agent(address):
  return functions.mintAgents(address).call()
def mint(receiver, amount, tx_args):
  return functions.mint(receiver, amount).transact(tx_args)
def set_mint_agent(address, state, tx_args):
  return functions.setMintAgent(address, state).transact(tx_args)

tx['from'] = accounts[1]
fails("setMintAgent with account 1 and account 1 as sender: fails because it's the wrong owner", set_mint_agent(accounts[1], True, tx))

tx['from'] = accounts[0]
succeeds("setMintAgent with account 1 and account 0 as sender: succeeds because it's the right owner", set_mint_agent(accounts[1], True, tx))

fails("mint to account 2 and account 0 as sender: fails because it's the wrong mint agent", mint(accounts[2], to_mint, tx))

tx['from'] = accounts[1]
succeeds("mint to account 2 and account 1 as sender: succeeds because it's the right mint agent", mint(accounts[2], to_mint, tx))


tx['from'] = accounts[0]
(mintable_token_contract, tx_hash) = deployer.deploy("./build/", "MintableTokenMock", tx, config['multisig_supply'], config['MW_address'], False)
receipt = web3.eth.waitForTransactionReceipt(tx_hash)
assert receipt.status == 1
functions = mintable_token_contract.functions

tx['from'] = accounts[1]
fails("setMintAgent with account 1 and account 1 as sender: fails because it's the wrong owner and can't mint", set_mint_agent(accounts[1], True, tx))
Пример #16
0
deployer = Deployer()
owner = web3.eth.accounts[0]
gas = 50000000
gas_price = 20000000000
tx = {"from": owner, "value": 0, "gas": gas, "gasPrice": gas_price}
config = config_f()
tokens_sold_example = 34 * 10**23

(token_tranche_pricing_contract, tx_hash) = deployer.deploy(
    "./build/",
    "TokenTranchePricingMock",
    tx,
)
receipt = web3.eth.waitForTransactionReceipt(tx_hash)
assert receipt.status == 1
functions = token_tranche_pricing_contract.functions


def get_tranches_length():
    return functions.getTranchesLength().call()


assert get_tranches_length() == 0
succeeds(
    "Configuration of TokenTranchePricing succeeds.",
    functions.configurateTokenTranchePricingMock(
        config['tranches']).transact(tx))
assert get_tranches_length() == 2
time.sleep(4)
assert functions.getCurrentPriceMock(tokens_sold_example).call() == 350
web3.miner.stop()
Пример #17
0
 tx_hash) = deployer.deploy("./build/", "CrowdsaleToken", tx,
                            config["multisig_supply"],
                            config["token_decimals"], config["MW_address"],
                            config["token_retriever_account"])
receipt = web3.eth.waitForTransactionReceipt(tx_hash)
assert receipt.status == 1
functions = crowdsale_token_contract.functions


def can_upgrade():
    return functions.canUpgrade().call()


def release_token_transfer(tx_args):
    return functions.releaseTokenTransfer().transact(tx_args)


assert functions.name().call() == "BurgerKoenig"
assert functions.symbol().call() == "BK"
assert functions.decimals().call() == config["token_decimals"]
assert functions.lost_and_found_master().call(
) == config["token_retriever_account"]
assert not can_upgrade()
fails("releaseTokenTransfer fails because sender isn't the releaseAgent.",
      release_token_transfer(tx))
succeeds("setReleaseAgent succeeds because the sender is the owner.",
         functions.setReleaseAgent(accounts[1]).transact(tx))
tx["from"] = accounts[1]
succeeds("releaseTokenTransfer succeeds because sender is the releaseAgent.",
         release_token_transfer(tx))
assert can_upgrade()
Пример #18
0
#!/usr/bin/env python3

import sys
sys.path.append("../deployment")
import deployer
from deployer import Deployer
from web3_interface import Web3Interface
from tx_checker import fails, succeeds

web3 = Web3Interface().w3
web3.miner.start(1)
deployer = Deployer()
owner = web3.eth.accounts[0]
new_owner = web3.eth.accounts[1]
gas = 5000000
gas_price = 20000000000
tx = {"from": owner, "value": 0, "gas": gas, "gasPrice": gas_price}

(ownable_contract, tx_hash) = deployer.deploy("./build/", "OwnableMock", tx,)
receipt = web3.eth.waitForTransactionReceipt(tx_hash)
assert receipt.status == 1
functions = ownable_contract.functions

def get_owner():
  return functions.owner().call()

assert get_owner() == owner
succeeds("Transfer ownership succeeds.", functions.transferOwnership(new_owner).transact(tx))
assert get_owner() == new_owner
web3.miner.stop()
Пример #19
0
new_owner = web3.eth.accounts[1]
tx = {'from': owner, 'gas': 100000000, 'gasPrice': 20000000000}
deployer = Deployer()
(haltable_contract, tx_hash) = deployer.deploy(
    "./build/",
    "Haltable",
    tx,
)
receipt = web3.eth.waitForTransactionReceipt(tx_hash)
assert receipt.status == 1
functions = haltable_contract.functions


def halted():
    return functions.halted().call()


def get_owner():
    return functions.owner().call()


assert halted() == False
succeeds("Halt succeeds", functions.halt().transact(tx))
assert halted() == True
succeeds("Unhalt succeeds", functions.unhalt().transact(tx))
assert halted() == False
assert get_owner() == owner
succeeds("Transfer ownership succeeds.",
         functions.transferOwnership(new_owner).transact(tx))
assert get_owner() == new_owner
web3.miner.stop()
Пример #20
0
 def require_customer_id(self):
     succeeds("Require Customer ID", super().set_require_customer_id(True))
     self.requiredCustomerId = True
    "./build/",
    "LostAndFoundTokenMock",
    tx,
)
receipt = web3.eth.waitForTransactionReceipt(tx_hash)
assert receipt.status == 1
functions = lost_and_found_token_contract.functions


def get_master():
    return functions.master().call()


def enable_lost_and_found(agent, tokens, token_contract, tx_args):
    return functions.enableLostAndFound(agent, tokens,
                                        token_contract).transact(tx_args)


assert get_master() == sender

tx['from'] = accounts[1]
fails(
    "enableLostAndFound with account 1 as sender: fails because it's the wrong master",
    enable_lost_and_found(agent_to_approve, tokens_to_approve,
                          standard_token_mock_contract.address, tx))

tx['from'] = accounts[0]
succeeds(
    "enableLostAndFound with account 0 as sender: succeeds because it's the right master",
    enable_lost_and_found(agent_to_approve, tokens_to_approve,
                          standard_token_mock_contract.address, tx))
Пример #22
0
 def unrequire_customer_id(self):
     succeeds("Unrequire Customer ID",
              super().set_require_customer_id(False))
     self.requiredCustomerId = False
Пример #23
0
  assert total_supply == get_total_supply()
  for x in accounts:
    assert token_balances[x] == balance_of(x)
  for n in accounts:
    for m in accounts:
      assert allowed[n][m] == allowance(n, m)

tx["from"] = accounts[3]
fails("Transfer 10000 from account 1 to account 2 with account 3: Fails because account 1 has no tokens", functions.transferFrom(accounts[1], accounts[2], value_transfer).transact(tx))

tx["from"] = accounts[1]
fails("Transfer 10000 from account 1 to account 2: Fails because account 1 has no tokens", functions.transfer(accounts[2], value_transfer).transact(tx))

fails("Burn 10000 from account 1: Fails because account 1 has no tokens", functions.burnTokensMock(accounts[1], value_transfer).transact(tx))

succeeds("subApproval of 10000 from account 1 to account 2: Succeeds because it has no restrictions", functions.subApproval(accounts[2], value_transfer).transact(tx))
sub_approval(accounts[1], accounts[2], value_transfer)

succeeds("addApproval of 10000 from account 1 to account 2: Succeeds because it has no restrictions", functions.addApproval(accounts[2], value_transfer).transact(tx))
allowed[accounts[1]][accounts[2]] += value_transfer

fails("Approve 10000 from account 1 to account 2: Fails because neither value or allowance are zero", functions.approve(accounts[2], value_transfer).transact(tx))

succeeds("Mint 100000 to account 1: Succeeds because mint has no restrictions", functions.mint(accounts[1], value_mint).transact(tx))
token_balances[accounts[1]] += value_mint
total_supply += value_mint

succeeds("Transfer 10000 from account 1 to account 2: Succeeds because account 1 has tokens", functions.transfer(accounts[2], value_transfer).transact(tx))
token_balances[accounts[1]] -= value_transfer
token_balances[accounts[2]] += value_transfer
Пример #24
0
 def require_signed_address(self, signer):
     succeeds("Require Signed Address",
              super().set_require_signed_address(True, signer))
     self.signer = signer
     self.requiredSignedAddress = True
Пример #25
0
tx = {"from": owner, "value": 0, "gas": gas, "gasPrice": gas_price}


def tx_from(tx_sender):
    return {"from": tx_sender, "value": 0, "gas": gas, "gasPrice": gas_price}


(token, deployment_hash) = deployer.deploy(
    "./build/",
    "ReleasableToken",
    tx,
)

#EXAMPLE succeeds("Unhalt succeeds", haltable_contract.functions.unhalt().transact(tx))

succeeds("ReleasableToken construction shouldn't fail.", deployment_hash)

assert token.functions.released().call() == False, "Shouldn't start released"

fails(
    "Shouldn't allow transfers from a non transfer agent",
    token.functions.transfer(random_receiver(),
                             random_contribution()).transact(
                                 tx_from(non_transfer_agent)))

fails(
    "Shouldn't allow extracting funds from a non transfer agent",
    token.functions.transferFrom(non_transfer_agent, random_receiver(),
                                 random_contribution()).transact(
                                     tx_from(non_transfer_agent)))
Пример #26
0

def total_upgraded():
    return functions.totalUpgraded().call()


print("Testing changeUpgradeMaster")
fails("changeUpgradeMaster fails calling with wrong master sender",
      functions.changeUpgradeMaster(newmaster).transact(txnewmaster))
assert upgrade_master() == master
fails(
    "changeUpgradeMaster fails setting address_zero and correct master sender",
    functions.changeUpgradeMaster(address_zero).transact(txmaster))
assert upgrade_master() == master
succeeds(
    "changeUpgradeMaster succeeds with correct master sender and setting new master",
    functions.changeUpgradeMaster(newmaster).transact(txmaster))
assert upgrade_master() == newmaster
succeeds(
    "changeUpgradeMaster succeeds with correct master sender and setting old master",
    functions.changeUpgradeMaster(master).transact(txnewmaster))
assert upgrade_master() == master

assert can_upgrade()
succeeds("setCanUp to False succeeds",
         functions.setCanUp(False).transact(txmaster))
assert not can_upgrade()
assert get_upgrade_state()
fails(
    "setUpgradeAgent fails with wrong master",
    functions.setUpgradeAgent(