Exemplo n.º 1
0
    def test_alice_propose_grant_to_bob_and_alice(self):
        ans = self.sim.tx(self.ALICE, self.contract, 0, ["pay", self.BOB.address, 1000])
        assert result(ans) == []

        self.sim.genesis.timestamp += 30 * 86400
        ans = self.sim.tx(self.ALICE, self.contract, 0, ["tick"])
        assert result(ans) == [1]

        assert self.get_account_balance(self.ALICE.address) == 995893222780
        assert self.get_account_timestamp(self.ALICE.address) == self.sim.genesis.timestamp
        assert self.get_account_tax_credits(self.ALICE.address) == 4106776220

        # Bob doesn't have enough capital to pay tax
        assert self.get_account_balance(self.BOB.address) == 1000
        assert self.get_account_timestamp(self.BOB.address) == self.sim.genesis.timestamp - 30 * 86400
        assert self.get_account_tax_credits(self.BOB.address) == 0

        assert self.get_commons_balance() == 4106776220

        # Propose 5000 grant for Bob to be paid out of Commons
        proposal_id_bob = self.get_proposal_id("grant to bob")
        print proposal_id_bob

        ans = self.sim.tx(self.ALICE, self.contract, 0, ["hash", "grant to bob"])
        assert result(ans) == [proposal_id_bob]

        ans = self.sim.tx(self.ALICE, self.contract, 0, ["propose", "grant to bob", self.BOB.address, 5000])
        assert result(ans) == [proposal_id_bob]

        assert self.get_account_balance(self.ALICE.address) == 995893222780
        assert self.get_account_timestamp(self.ALICE.address) == self.sim.genesis.timestamp
        assert self.get_account_tax_credits(self.ALICE.address) == 4106776220

        assert self.get_proposal_recipient("grant to bob") == self.BOB.address
        assert self.get_proposal_amount("grant to bob") == 5000
        assert self.get_proposal_votes("grant to bob") == 0

        assert self.get_proposal_list() == [coerce_addr_to_hex(proposal_id_bob)]

        # Make sure charlie's account exists
        ans = self.sim.tx(self.BOB, self.contract, 0, ["pay", self.CHARLIE.address, 250])
        assert result(ans) == []

        # Propose 1000 grant for Charlie to be paid out of Commons
        proposal_id_charlie = self.get_proposal_id("grant to charlie")
        ans = self.sim.tx(self.ALICE, self.contract, 0, ["propose", "grant to charlie", self.CHARLIE.address, 1000])
        assert result(ans) == [proposal_id_charlie]

        assert self.get_proposal_recipient("grant to charlie") == self.CHARLIE.address
        assert self.get_proposal_amount("grant to charlie") == 1000
        assert self.get_proposal_votes("grant to charlie") == 0

        assert self.get_proposal_list() == [coerce_addr_to_hex(proposal_id_bob), coerce_addr_to_hex(proposal_id_charlie)]
Exemplo n.º 2
0
 def get_proposal_list(self):
     nr_proposals = self.sim.get_storage_data(self.contract,
                                              coerce_to_bytes(2**162 - 1))
     proposals = []
     for idx in range(nr_proposals):
         proposals.append(
             coerce_addr_to_hex(
                 self.sim.get_storage_data(self.contract,
                                           coerce_to_bytes(2**162 + idx))))
     return proposals
Exemplo n.º 3
0
 def get_account_list(self):
     nr_accounts = self.sim.get_storage_data(self.contract,
                                             coerce_to_bytes(2**160 - 1))
     accounts = []
     for idx in range(nr_accounts):
         accounts.append(
             coerce_addr_to_hex(
                 self.sim.get_storage_data(self.contract,
                                           coerce_to_bytes(2**160 + idx))))
     return accounts
Exemplo n.º 4
0
 def get_proposal_list(self):
     nr_proposals = self.sim.get_storage_data(self.contract, coerce_to_bytes(2**162-1))
     proposals = []
     for idx in range(nr_proposals):
         proposals.append(coerce_addr_to_hex(self.sim.get_storage_data(self.contract, coerce_to_bytes(2**162 + idx))))
     return proposals
Exemplo n.º 5
0
 def get_proposal_recipient(self, proposal):
     proposal_id = self.get_proposal_id(proposal)
     return coerce_addr_to_hex(self.sim.get_storage_data(self.contract, coerce_to_bytes(proposal_id + 2**163)))
Exemplo n.º 6
0
 def get_account_list(self):
     nr_accounts = self.sim.get_storage_data(self.contract, coerce_to_bytes(2**160-1))
     accounts = []
     for idx in range(nr_accounts):
         accounts.append(coerce_addr_to_hex(self.sim.get_storage_data(self.contract, coerce_to_bytes(2**160 + idx))))
     return accounts
Exemplo n.º 7
0
 def get_proposal_recipient(self, proposal):
     proposal_id = self.get_proposal_id(proposal)
     return coerce_addr_to_hex(
         self.sim.get_storage_data(self.contract,
                                   coerce_to_bytes(proposal_id + 2**163)))
Exemplo n.º 8
0
    def test_alice_propose_grant_to_bob_and_alice(self):
        ans = self.sim.tx(self.ALICE, self.contract, 0,
                          ["pay", self.BOB.address, 1000])
        assert result(ans) == []

        self.sim.genesis.timestamp += 30 * 86400
        ans = self.sim.tx(self.ALICE, self.contract, 0, ["tick"])
        assert result(ans) == [1]

        assert self.get_account_balance(self.ALICE.address) == 995893222780
        assert self.get_account_timestamp(
            self.ALICE.address) == self.sim.genesis.timestamp
        assert self.get_account_tax_credits(self.ALICE.address) == 4106776220

        # Bob doesn't have enough capital to pay tax
        assert self.get_account_balance(self.BOB.address) == 1000
        assert self.get_account_timestamp(
            self.BOB.address) == self.sim.genesis.timestamp - 30 * 86400
        assert self.get_account_tax_credits(self.BOB.address) == 0

        assert self.get_commons_balance() == 4106776220

        # Propose 5000 grant for Bob to be paid out of Commons
        proposal_id_bob = self.get_proposal_id("grant to bob")
        print proposal_id_bob

        ans = self.sim.tx(self.ALICE, self.contract, 0,
                          ["hash", "grant to bob"])
        assert result(ans) == [proposal_id_bob]

        ans = self.sim.tx(self.ALICE, self.contract, 0,
                          ["propose", "grant to bob", self.BOB.address, 5000])
        assert result(ans) == [proposal_id_bob]

        assert self.get_account_balance(self.ALICE.address) == 995893222780
        assert self.get_account_timestamp(
            self.ALICE.address) == self.sim.genesis.timestamp
        assert self.get_account_tax_credits(self.ALICE.address) == 4106776220

        assert self.get_proposal_recipient("grant to bob") == self.BOB.address
        assert self.get_proposal_amount("grant to bob") == 5000
        assert self.get_proposal_votes("grant to bob") == 0

        assert self.get_proposal_list() == [
            coerce_addr_to_hex(proposal_id_bob)
        ]

        # Make sure charlie's account exists
        ans = self.sim.tx(self.BOB, self.contract, 0,
                          ["pay", self.CHARLIE.address, 250])
        assert result(ans) == []

        # Propose 1000 grant for Charlie to be paid out of Commons
        proposal_id_charlie = self.get_proposal_id("grant to charlie")
        ans = self.sim.tx(
            self.ALICE, self.contract, 0,
            ["propose", "grant to charlie", self.CHARLIE.address, 1000])
        assert result(ans) == [proposal_id_charlie]

        assert self.get_proposal_recipient(
            "grant to charlie") == self.CHARLIE.address
        assert self.get_proposal_amount("grant to charlie") == 1000
        assert self.get_proposal_votes("grant to charlie") == 0

        assert self.get_proposal_list() == [
            coerce_addr_to_hex(proposal_id_bob),
            coerce_addr_to_hex(proposal_id_charlie)
        ]