Exemplo n.º 1
0
Arquivo: run.py Projeto: LiteBit/DAO
def run(framework):
    # if deployment did not already happen do it now
    if not framework.dao_addr:
        framework.run_scenario('deploy')
    else:
        print(
            "WARNING: Running the failed funding 2 scenario with a "
            "pre-deployed DAO contract. Closing time is {} which is "
            "approximately {} seconds from now.".format(
                datetime.fromtimestamp(framework.closing_time).strftime(
                    '%Y-%m-%d %H:%M:%S'
                ),
                framework.remaining_time()
            )
        )

    accounts_num = len(framework.accounts)
    if accounts_num * 2 >= framework.args.deploy_min_value - 4:
        print("Please increase the minimum funding goal for the scenario.")
        sys.exit(1)

    sale_secs = framework.remaining_time()
    total_supply = framework.args.deploy_min_value - 4
    proxy_amounts = constrained_sum_sample_pos(
        accounts_num, total_supply / 2
    )
    normal_amounts = constrained_sum_sample_pos(
        accounts_num, total_supply / 2
    )
    framework.token_amounts = [
        sum(x) for x in zip(proxy_amounts[::-1], normal_amounts)
    ]
    framework.total_supply = sum(framework.token_amounts)
    framework.create_js_file(
        substitutions={
            "dao_abi": framework.dao_abi,
            "dao_address": framework.dao_addr,
            "wait_ms": (sale_secs-3)*1000,
            "proxy_amounts": arr_str(proxy_amounts),
            "normal_amounts": arr_str(normal_amounts)
        }
    )
    print(
        "Notice: Funding period is {} seconds so the test will wait "
        "as much".format(sale_secs)
    )
    framework.execute(expected={
        "dao_funded": False,
        "total_supply": framework.total_supply,
        "refund": framework.token_amounts
    })
Exemplo n.º 2
0
Arquivo: run.py Projeto: CJGuest/DAO
def run(ctx):
    ctx.assert_scenario_ran('deploy')

    sale_secs = ctx.remaining_time()
    ctx.total_supply = ctx.args.deploy_min_value + random.randint(1, 100)
    ctx.token_amounts = constrained_sum_sample_pos(
        len(ctx.accounts), ctx.total_supply
    )
    ctx.create_js_file(substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_addr,
            "wait_ms": (sale_secs-3)*1000,
            "amounts": arr_str(ctx.token_amounts)
        }
    )
    print(
        "Notice: Fueling period is {} seconds so the test will wait "
        "as much".format(sale_secs)
    )

    ctx.execute(expected={
        "dao_fueled": True,
        "total_supply": ctx.total_supply,
        "balances": ctx.token_amounts,
        "user0_after": ctx.token_amounts[0],
    })
Exemplo n.º 3
0
    def prepare_test_split(self, split_gas):
        if self.prop_id != 2:
            # run the rewards scenario first
            self.run_test_rewards()

        debate_secs = 15
        votes = create_votes_array(
            self.token_amounts,
            not self.args.proposal_fail
        )
        self.create_js_file(
            'split',
            {
                "dao_abi": self.dao_abi,
                "dao_address": self.dao_addr,
                "debating_period": debate_secs,
                "split_gas": split_gas,
                "votes": arr_str(votes),
                "prop_id": self.next_proposal_id()
            }
        )
        print(
            "Notice: Debate period is {} seconds so the test will wait "
            "as much".format(debate_secs)
        )
        output = self.run_script('split.js')
        return votes, output
Exemplo n.º 4
0
def prepare_test_split(ctx, split_gas):
    ctx.assert_scenario_ran('rewards')

    votes = create_votes_array(
        ctx.token_amounts,
        not ctx.args.proposal_fail,
        True
    )
    # remember the account information of the first True votes. They will be
    # the child dao curator in this scenario and grandchild curator in the next
    iterator = (
        (ctx.accounts[i], ctx.token_amounts[i])
        for i, vote in enumerate(votes) if vote is True
    )
    (ctx.child_dao_curator, _) = next(iterator)
    (ctx.grandchild_dao_curator, ctx.grandchild_dao_curator_before) = next(iterator)
    ctx.create_js_file(substitutions={
        "dao_abi": ctx.dao_abi,
        "dao_address": ctx.dao_address,
        "debating_period": ctx.args.split_debate_seconds,
        "split_execution_period": ctx.args.split_execution_period,
        "split_gas": split_gas,
        "votes": arr_str(votes),
        "child_dao_curator": ctx.child_dao_curator
        }
    )
    print(
        "Notice: Debate period is {} seconds so the test will wait "
        "as much".format(ctx.args.split_debate_seconds)
    )
    return votes
Exemplo n.º 5
0
Arquivo: run.py Projeto: AlmavivA/DAO
def run(ctx):
    ctx.assert_scenario_ran('split')
    # right after the split scenario ran, wait sufficient time for the
    # child_dao closingTime() to be reached.
    time_now = round(time.time())
    if time_now < ctx.child_dao_closing_time:
        wait_for_secs = ctx.child_dao_closing_time - time_now
        print(
            "The child DAO's closing time is not yet reached. Test will wait "
            "for {} seconds.".format(wait_for_secs)
        )
        time.sleep(wait_for_secs)
    ctx.create_js_file(substitutions={
        "dao_abi": ctx.dao_abi,
        "dao_address": ctx.dao_addr,
        "split_execution_period": ctx.args.split_execution_period,
        "child_dao_curator": ctx.child_dao_curator,
        "grandchild_dao_curator": ctx.grandchild_dao_curator,
        "child_dao_address": ctx.child_dao_address,
        "child_dao_members": arr_str(ctx.child_dao_members),
        "proposal_deposit": ctx.args.proposal_deposit,
        "debating_period": ctx.args.proposal_debate_seconds
        }
    )
    print(
        "Notice: Debate period is {} seconds so the test will wait "
        "as much".format(ctx.args.proposal_debate_seconds)
    )

    ctx.execute(expected={
        "grandchild_curator_dao_balance": ctx.grandchild_dao_curator_before,
        "split_proposal_passed": True
    })
Exemplo n.º 6
0
Arquivo: run.py Projeto: tad88dev/DAO
def run(ctx):
    ctx.assert_scenario_ran("split")
    # right after the split scenario ran, wait sufficient time for the
    # child_dao closingTime() to be reached.
    time_now = round(time.time())
    if time_now < ctx.child_dao_closing_time:
        wait_for_secs = ctx.child_dao_closing_time - time_now
        print(
            "The child DAO's closing time is not yet reached. Test will wait " "for {} seconds.".format(wait_for_secs)
        )
        time.sleep(wait_for_secs)
    transaction_bytecode = calculate_bytecode("updateClientAddress", ("address", ctx.child_dao_address))
    ctx.create_js_file(
        substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_address,
            "split_execution_period": ctx.args.split_execution_period,
            "child_dao_curator": ctx.child_dao_curator,
            "child_dao_address": ctx.child_dao_address,
            "offer_abi": ctx.offer_abi,
            "offer_address": ctx.offer_address,
            "child_dao_members": arr_str(ctx.child_dao_members),
            "proposal_deposit": ctx.args.proposal_deposit,
            "debating_period": ctx.args.proposal_debate_seconds,
            "transaction_bytecode": transaction_bytecode,
        }
    )
    print(
        "Notice: Debate period is {} seconds so the test will wait " "as much".format(ctx.args.proposal_debate_seconds)
    )

    ctx.execute(expected={"offer_client": ctx.child_dao_address, "offer_original_client": ctx.dao_address})
Exemplo n.º 7
0
Arquivo: run.py Projeto: dqryscdjj/DAO
def run(ctx):
    ctx.assert_scenario_ran('fuel')

    votes = create_votes_array_for_quorum(ctx.token_amounts, 0.4, True)
    # let's just use an existing account
    newAddress = ctx.accounts[4]
    bytecode = calculate_bytecode('newContract', ("address", newAddress))
    ctx.create_js_file(substitutions={
        "dao_abi": ctx.dao_abi,
        "dao_address": ctx.dao_addr,
        "new_contract_address": newAddress,
        "proposal_deposit": ctx.args.proposal_deposit,
        "votes": arr_str(votes),
        "transaction_bytecode": bytecode,
        "debating_period": ctx.args.proposal_debate_seconds,
        "prop_id": ctx.next_proposal_id()
    })
    print(
        "Notice: Debate period is {} seconds so the test will wait "
        "as much".format(ctx.args.proposal_debate_seconds)
    )

    ctx.execute(expected={
        "proposal_passed": False,
        "new_contract_balance": 0,
        "dao_balance_diff": 0
    })
Exemplo n.º 8
0
Arquivo: run.py Projeto: CJGuest/DAO
def run(ctx):
    ctx.assert_scenario_ran('deploy')

    accounts_num = len(ctx.accounts)
    sale_secs = ctx.remaining_time()
    ctx.total_supply = random.randint(5, ctx.args.deploy_min_value - 4)
    ctx.token_amounts = constrained_sum_sample_pos(
        accounts_num, ctx.total_supply
    )
    ctx.create_js_file(substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_addr,
            "wait_ms": (sale_secs-3)*1000,
            "amounts": arr_str(ctx.token_amounts)
        }
    )
    print(
        "Notice: Fueling period is {} seconds so the test will wait "
        "as much".format(sale_secs)
    )
    ctx.execute(expected={
        "dao_fueled": False,
        "total_supply": ctx.total_supply,
        "refund": ctx.token_amounts
    })
Exemplo n.º 9
0
def run(ctx):
    ctx.assert_scenario_ran('deploy')

    accounts_num = len(ctx.accounts)
    if accounts_num * 2 >= ctx.args.deploy_min_tokens_to_create - 4:
        print("Please increase the minimum fueling goal for the scenario.")
        sys.exit(1)

    creation_secs = ctx.remaining_time()
    total_supply = ctx.args.deploy_min_tokens_to_create - 4
    proxy_amounts = constrained_sum_sample_pos(
        accounts_num, total_supply / 2
    )
    normal_amounts = constrained_sum_sample_pos(
        accounts_num, total_supply / 2
    )
    ctx.token_amounts = [
        sum(x) for x in zip(proxy_amounts[::-1], normal_amounts)
    ]
    ctx.total_supply = sum(ctx.token_amounts)
    ctx.create_js_file(
        substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_address,
            "wait_ms": (creation_secs-3)*1000,
            "proxy_amounts": arr_str(proxy_amounts),
            "normal_amounts": arr_str(normal_amounts)
        }
    )
    print(
        "Notice: Fueling period is {} seconds so the test will wait "
        "as much".format(creation_secs)
    )
    ctx.execute(expected={
        "dao_fueled": False,
        "total_supply": ctx.total_supply,
        "refund": ctx.token_amounts
    })
Exemplo n.º 10
0
    def run_test_proposal(self):
        if not self.token_amounts:
            # run the funding scenario first
            self.run_test_fund()

        debate_secs = 20
        minamount = 2  # is determined by the total costs + one time costs
        amount = random.randint(minamount, sum(self.token_amounts))
        votes = create_votes_array(
            self.token_amounts,
            not self.args.proposal_fail
        )
        yay, nay = count_token_votes(self.token_amounts, votes)
        # self.create_proposal_js(amount, debate_secs, votes)
        self.create_js_file(
            'proposal',
            {
                "dao_abi": self.dao_abi,
                "dao_address": self.dao_addr,
                "offer_abi": self.offer_abi,
                "offer_address": self.offer_addr,
                "offer_amount": amount,
                "offer_desc": 'Test Proposal',
                "proposal_deposit": self.args.proposal_deposit,
                "transaction_bytecode": '0x2ca15122',  # solc --hashes SampleOffer.sol
                "debating_period": debate_secs,
                "votes": arr_str(votes)
            }
        )
        print(
            "Notice: Debate period is {} seconds so the test will wait "
            "as much".format(debate_secs)
        )
        output = self.run_script('proposal.js')
        eval_test('proposal', output, {
            "dao_proposals_number": "1",
            "proposal_passed": True,
            "proposal_yay": yay,
            "proposal_nay": nay,
            "calculated_deposit": self.args.proposal_deposit,
            "onetime_costs": self.args.offer_onetime_costs,
            "deposit_returned": True,
            "offer_promise_valid": True
        })
        self.prop_id = 1
Exemplo n.º 11
0
Arquivo: run.py Projeto: AlmavivA/DAO
def run(ctx):
    ctx.assert_scenario_ran('deploy')

    ctx.total_supply = (
        ctx.args.deploy_min_tokens_to_create + random.randint(1, 100)
    )
    ctx.token_amounts = constrained_sum_sample_pos(
        len(ctx.accounts), ctx.total_supply
    )
    ctx.create_js_file(substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_addr,
            "amounts": arr_str(ctx.token_amounts)
        }
    )

    ctx.execute(expected={
        "min_quorum_same": True
    })
Exemplo n.º 12
0
    def run_test_fund(self):
        # if deployment did not already happen do it now
        if not self.dao_addr:
            self.run_test_deploy()
        else:
            print(
                "WARNING: Running the funding scenario with a pre-deployed "
                "DAO contract. Closing time is {} which is approximately {} "
                "seconds from now.".format(
                    datetime.fromtimestamp(self.closing_time).strftime(
                        '%Y-%m-%d %H:%M:%S'
                    ),
                    self.closing_time - ts_now()
                )
            )

        sale_secs = self.closing_time - ts_now()
        self.total_supply = self.min_value + random.randint(1, 100)
        self.token_amounts = constrained_sum_sample_pos(
            len(self.accounts), self.total_supply
        )
        self.create_js_file(
            'fund',
            {
                "dao_abi": self.dao_abi,
                "dao_address": self.dao_addr,
                "wait_ms": (sale_secs-3)*1000,
                "amounts": arr_str(self.token_amounts)
            }
        )
        print(
            "Notice: Funding period is {} seconds so the test will wait "
            "as much".format(sale_secs)
        )
        output = self.run_script('fund.js')
        eval_test('fund', output, {
            "dao_funded": True,
            "total_supply": self.total_supply,
            "balances": self.token_amounts,
            "user0_after": self.token_amounts[0],
        })
Exemplo n.º 13
0
Arquivo: run.py Projeto: FelixA/DAO
def prepare_test_split(ctx, split_gas):
    ctx.assert_scenario_ran('rewards')

    votes = create_votes_array(
        ctx.token_amounts,
        not ctx.args.proposal_fail
    )
    ctx.create_js_file(substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_addr,
            "debating_period": ctx.args.split_debate_seconds,
            "split_gas": split_gas,
            "votes": arr_str(votes),
            "prop_id": ctx.next_proposal_id()
        }
    )
    print(
        "Notice: Debate period is {} seconds so the test will wait "
        "as much".format(ctx.args.split_debate_seconds)
    )
    return votes
Exemplo n.º 14
0
Arquivo: run.py Projeto: CJGuest/DAO
def run(ctx):
    ctx.assert_scenario_ran('fuel')

    minamount = 2  # is determined by the total costs + one time costs
    amount = random.randint(minamount, sum(ctx.token_amounts))
    votes = create_votes_array(
        ctx.token_amounts,
        not ctx.args.proposal_fail,
        False
    )
    yay, nay = count_token_votes(ctx.token_amounts, votes)
    ctx.create_js_file(substitutions={
        "dao_abi": ctx.dao_abi,
        "dao_address": ctx.dao_addr,
        "offer_abi": ctx.offer_abi,
        "offer_address": ctx.offer_addr,
        "offer_amount": amount,
        "offer_desc": 'Test Proposal',
        "proposal_deposit": ctx.args.proposal_deposit,
        "transaction_bytecode": '0x2ca15122',  # solc --hashes SampleOffer.sol
        "debating_period": ctx.args.proposal_debate_seconds,
        "votes": arr_str(votes),
        "should_halve_minquorum": str(ctx.args.proposal_halveminquorum).lower()
    })
    print(
        "Notice: Debate period is {} seconds so the test will wait "
        "as much".format(ctx.args.proposal_debate_seconds)
    )

    ctx.execute(expected={
        "dao_proposals_number": "1",
        "proposal_passed": True,
        "proposal_yay": yay,
        "proposal_nay": nay,
        "calculated_deposit": ctx.args.proposal_deposit,
        "onetime_costs": ctx.args.deploy_onetime_costs,
        "deposit_returned": True,
        "offer_promise_valid": True
    })
Exemplo n.º 15
0
Arquivo: run.py Projeto: LiteBit/DAO
def run(framework):
    # if deployment did not already happen do it now
    if not framework.dao_addr:
        framework.run_scenario('deploy')
    else:
        print(
            "WARNING: Running the funding scenario with a pre-deployed "
            "DAO contract. Closing time is {} which is approximately {} "
            "seconds from now.".format(
                datetime.fromtimestamp(framework.closing_time).strftime(
                    '%Y-%m-%d %H:%M:%S'
                ),
                framework.remaining_time()
            )
        )

    sale_secs = framework.remaining_time()
    framework.total_supply = framework.args.deploy_min_value + random.randint(1, 100)
    framework.token_amounts = constrained_sum_sample_pos(
        len(framework.accounts), framework.total_supply
    )
    framework.create_js_file(substitutions={
            "dao_abi": framework.dao_abi,
            "dao_address": framework.dao_addr,
            "wait_ms": (sale_secs-3)*1000,
            "amounts": arr_str(framework.token_amounts)
        }
    )
    print(
        "Notice: Funding period is {} seconds so the test will wait "
        "as much".format(sale_secs)
    )

    framework.execute(expected={
        "dao_funded": True,
        "total_supply": framework.total_supply,
        "balances": framework.token_amounts,
        "user0_after": framework.token_amounts[0],
    })
Exemplo n.º 16
0
Arquivo: run.py Projeto: Codzart/DAO
def run(ctx):
    ctx.assert_scenario_ran('deploy')

    creation_secs = ctx.remaining_time()
    ctx.total_supply = 150
    ctx.token_amounts = [10 , 20 , 30, 40, 50]
    ctx.create_js_file(substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_address,
            "wait_ms": (creation_secs-3)*1000,
            "amounts": arr_str(ctx.token_amounts)
        }
    )
    print(
        "Notice: Fueling period is {} seconds so the test will wait "
        "as much".format(creation_secs)
    )

    ctx.execute(expected={
        "dao_fueled": True,
        "total_supply": 150,
        "balances": [10,20,30,40,50]
    })
Exemplo n.º 17
0
Arquivo: run.py Projeto: LiteBit/DAO
def prepare_test_split(framework, split_gas):
    if framework.prop_id != 2:
        # run the rewards scenario first
        framework.run_scenario('rewards')

    votes = create_votes_array(
        framework.token_amounts,
        not framework.args.proposal_fail
    )
    framework.create_js_file(substitutions={
            "dao_abi": framework.dao_abi,
            "dao_address": framework.dao_addr,
            "debating_period": framework.args.split_debate_seconds,
            "split_gas": split_gas,
            "votes": arr_str(votes),
            "prop_id": framework.next_proposal_id()
        }
    )
    print(
        "Notice: Debate period is {} seconds so the test will wait "
        "as much".format(framework.args.split_debate_seconds)
    )
    return votes
Exemplo n.º 18
0
def run(ctx):
    ctx.assert_scenario_ran('deploy')

    accounts_num = len(ctx.accounts)
    sale_secs = ctx.remaining_time()
    ctx.total_supply = random.randint(5, ctx.args.deploy_min_value - 4)
    ctx.token_amounts = constrained_sum_sample_pos(accounts_num,
                                                   ctx.total_supply)
    ctx.create_js_file(
        substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_addr,
            "wait_ms": (sale_secs - 3) * 1000,
            "amounts": arr_str(ctx.token_amounts)
        })
    print("Notice: Funding period is {} seconds so the test will wait "
          "as much".format(sale_secs))
    ctx.execute(
        expected={
            "dao_funded": False,
            "total_supply": ctx.total_supply,
            "refund": ctx.token_amounts
        })
Exemplo n.º 19
0
def run(ctx):
    ctx.assert_scenario_ran('fuel')

    minamount = 2  # is determined by the total costs + one time costs
    amount = random.randint(minamount, sum(ctx.token_amounts))
    votes = create_votes_array(ctx.token_amounts, not ctx.args.proposal_fail,
                               False)
    yay, nay = count_token_votes(ctx.token_amounts, votes)
    ctx.create_js_file(
        substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_addr,
            "offer_abi": ctx.offer_abi,
            "offer_address": ctx.offer_addr,
            "offer_amount": amount,
            "offer_desc": 'Test Proposal',
            "proposal_deposit": ctx.args.proposal_deposit,
            "transaction_bytecode":
            '0x2ca15122',  # solc --hashes SampleOffer.sol
            "debating_period": ctx.args.proposal_debate_seconds,
            "votes": arr_str(votes),
            "should_halve_minquorum": str(
                ctx.args.proposal_halveminquorum).lower()
        })
    print("Notice: Debate period is {} seconds so the test will wait "
          "as much".format(ctx.args.proposal_debate_seconds))

    ctx.execute(
        expected={
            "dao_proposals_number": "1",
            "proposal_yay": yay,
            "proposal_nay": nay,
            "calculated_deposit": ctx.args.proposal_deposit,
            "onetime_costs": ctx.args.deploy_onetime_costs,
            "deposit_returned": True,
            "offer_promise_valid": True
        })
Exemplo n.º 20
0
def run(ctx):
    ctx.assert_scenario_ran('deploy')

    creation_secs = ctx.remaining_time()
    ctx.total_supply = (
        ctx.args.deploy_min_tokens_to_create + random.randint(1, 100)
    )
    ctx.token_amounts = constrained_sum_sample_pos(
        len(ctx.accounts), ctx.total_supply
    )
    ctx.create_js_file(substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_address,
            "wait_ms": (creation_secs-3)*1000,
            "amounts": arr_str(ctx.token_amounts)
        }
    )
    print(
        "Notice: Fueling period is {} seconds so the test will wait "
        "as much".format(creation_secs)
    )

    adjusted_amounts = (
        [x/1.5 for x in ctx.token_amounts]
        if ctx.scenario_uses_extrabalance() else ctx.token_amounts
    )
    adjusted_supply = (
        ctx.total_supply / 1.5
        if ctx.scenario_uses_extrabalance() else ctx.total_supply
    )

    ctx.execute(expected={
        "dao_fueled": True,
        "total_supply": adjusted_supply,
        "balances": adjusted_amounts,
        "user0_after": adjusted_amounts[0]
    })
Exemplo n.º 21
0
def run(ctx):
    ctx.assert_scenario_ran('deploy')

    sale_secs = ctx.remaining_time()
    ctx.total_supply = ctx.args.deploy_min_value + random.randint(1, 100)
    ctx.token_amounts = constrained_sum_sample_pos(len(ctx.accounts),
                                                   ctx.total_supply)
    ctx.create_js_file(
        substitutions={
            "dao_abi": ctx.dao_abi,
            "dao_address": ctx.dao_addr,
            "wait_ms": (sale_secs - 3) * 1000,
            "amounts": arr_str(ctx.token_amounts)
        })
    print("Notice: Fueling period is {} seconds so the test will wait "
          "as much".format(sale_secs))

    ctx.execute(
        expected={
            "dao_fueled": True,
            "total_supply": ctx.total_supply,
            "balances": ctx.token_amounts,
            "user0_after": ctx.token_amounts[0],
        })