コード例 #1
0
    def test_claim_has_unique_entropy(self):
        self.s.mine(1)

        with assert_max_gas_cost(self.s.block, SPIN_GAS):
            assert self.c.spin(5, value=5 * ETHER) == 1

        with assert_max_gas_cost(self.s.block, SPIN_GAS):
            assert self.c.spin(5, sender=tester.k1, value=5 * ETHER) == 1

        current_round = self.c.get_current_round()
        assert current_round == 1

        current_round = self.c.get_current_round(sender=tester.k1)
        assert current_round == 2

        self.s.mine(1)

        with assert_max_gas_cost(self.s.block, CLAIM_GAS):
            assert self.c.claim(1) == 1

        with assert_max_gas_cost(self.s.block, CLAIM_GAS):
            assert self.c.claim(2, sender=tester.k1) == 1

        player1, block1, bet1, result1, entropy1, status1 = self.c.get_round(1)
        player2, block2, bet2, result2, entropy2, status2 = self.c.get_round(2)
        assert address(player1) == tester.a0.encode('hex')
        assert address(player2) == tester.a1.encode('hex')
        assert entropy1 != entropy2
コード例 #2
0
    def test_claim_has_unique_entropy(self):
        self.s.mine(1)

        with assert_max_gas_cost(self.s.block, SPIN_GAS):
            assert self.c.spin(5, value=5 * ETHER) == 1

        with assert_max_gas_cost(self.s.block, SPIN_GAS):
            assert self.c.spin(5, sender=tester.k1, value=5 * ETHER) == 1

        current_round = self.c.get_current_round()
        assert current_round == 1

        current_round = self.c.get_current_round(sender=tester.k1)
        assert current_round == 2

        self.s.mine(1)

        with assert_max_gas_cost(self.s.block, CLAIM_GAS):
            assert self.c.claim(1) == 1

        with assert_max_gas_cost(self.s.block, CLAIM_GAS):
            assert self.c.claim(2, sender=tester.k1) == 1

        player1, block1, bet1, result1, entropy1, status1 = self.c.get_round(1)
        player2, block2, bet2, result2, entropy2, status2 = self.c.get_round(2)
        assert address(player1) == tester.a0.encode('hex')
        assert address(player2) == tester.a1.encode('hex')
        assert entropy1 != entropy2
コード例 #3
0
    def test_buying_ticket(self):
        numbers = [1, 3, 4, 5, 9, 35]
        self.contract.call(START_LOTTO)
        ticket_id = self.contract.call(BUY_TICKET, numbers)[0]

        assert_equal(address(self.contract.call(GET_TICKET_OWNER, [ticket_id])[0]), t.a0)
        assert_equal(self.contract.call(GET_TICKET_NUMBERS, [ticket_id]), numbers)

        new_numbers = [1, 5, 7, 8, 10, 35]
        new_ticket_id = self.contract.call(BUY_TICKET, new_numbers)[0]

        assert_equal(address(self.contract.call(GET_TICKET_OWNER, [new_ticket_id])[0]), t.a0)
        assert_equal(self.contract.call(GET_TICKET_NUMBERS, [new_ticket_id]), new_numbers)
コード例 #4
0
    def _spin_mine_claim(self, amount, premine, expected_result):
        self.s.mine(premine)

        with assert_max_gas_cost(self.s.block, SPIN_GAS):
            assert self.c.spin(amount, value=amount * ETHER) == 1

        self.s.mine(1)
        balance_before = self.s.block.get_balance(tester.a0)

        with assert_max_gas_cost(self.s.block, CLAIM_GAS):
            assert self.c.claim(1) == 1

        player, block, bet, result, entropy, status = self.c.get_round(1)
        assert address(player) == tester.a0.encode('hex')
        assert block == premine
        assert bet == amount
        assert entropy != 0
        assert status == 2  # done
        assert result == expected_result

        balance_after = self.s.block.get_balance(tester.a0)
        assert balance_after - balance_before == expected_result * ETHER

        current_round = self.c.get_current_round()
        assert current_round == 1

        assert self.c.get_stats() == [1, amount, expected_result]
コード例 #5
0
    def _spin_mine_claim(self, amount, premine, expected_result):
        self.s.mine(premine)

        with assert_max_gas_cost(self.s.block, SPIN_GAS):
            assert self.c.spin(amount, value=amount * ETHER) == 1

        self.s.mine(1)
        balance_before = self.s.block.get_balance(tester.a0)

        with assert_max_gas_cost(self.s.block, CLAIM_GAS):
            assert self.c.claim(1) == 1

        player, block, bet, result, entropy, status = self.c.get_round(1)
        assert address(player) == tester.a0.encode('hex')
        assert block == premine
        assert bet == amount
        assert entropy != 0
        assert status == 2  # done
        assert result == expected_result

        balance_after = self.s.block.get_balance(tester.a0)
        assert balance_after - balance_before == expected_result * ETHER

        current_round = self.c.get_current_round()
        assert current_round == 1

        assert self.c.get_stats() == [1, amount, expected_result]
コード例 #6
0
    def test_transfering_ticket(self):
        numbers = [1, 3, 4, 5, 9, 35]
        self.contract.call(START_LOTTO)
        ticket_id = self.contract.call(BUY_TICKET, numbers)[0]

        self.contract.call(TRANSFER_TICKET, [ticket_id, t.a1])

        assert_equal(address(self.contract.call(GET_TICKET_OWNER, [ticket_id])[0]), t.a1)
コード例 #7
0
    def test_transfering_ticket(self):
        numbers = [1, 3, 4, 5, 9, 35]
        self.contract.call(START_LOTTO)
        ticket_id = self.contract.call(BUY_TICKET, numbers)[0]

        self.contract.call(TRANSFER_TICKET, [ticket_id, t.a1])

        assert_equal(
            address(self.contract.call(GET_TICKET_OWNER, [ticket_id])[0]),
            t.a1)
コード例 #8
0
    def test_buying_ticket(self):
        numbers = [1, 3, 4, 5, 9, 35]
        self.contract.call(START_LOTTO)
        ticket_id = self.contract.call(BUY_TICKET, numbers)[0]

        assert_equal(
            address(self.contract.call(GET_TICKET_OWNER, [ticket_id])[0]),
            t.a0)
        assert_equal(self.contract.call(GET_TICKET_NUMBERS, [ticket_id]),
                     numbers)

        new_numbers = [1, 5, 7, 8, 10, 35]
        new_ticket_id = self.contract.call(BUY_TICKET, new_numbers)[0]

        assert_equal(
            address(self.contract.call(GET_TICKET_OWNER, [new_ticket_id])[0]),
            t.a0)
        assert_equal(self.contract.call(GET_TICKET_NUMBERS, [new_ticket_id]),
                     new_numbers)
コード例 #9
0
    def test_spin_valid_bet(self):
        with assert_max_gas_cost(self.s.block, SPIN_GAS):
            assert self.c.spin(5, value=5 * ETHER) == 1

        current_round = self.c.get_current_round()
        assert current_round == 1

        player, block, bet, result, entropy, status = self.c.get_round(current_round)
        assert address(player) == tester.a0.encode('hex')
        assert block == 0
        assert bet == 5
        assert result == 0
        assert entropy == 0
        assert status == 1  # spinning

        assert self.c.get_stats() == [1, 5, 0]
コード例 #10
0
    def test_spin_valid_bet(self):
        with assert_max_gas_cost(self.s.block, SPIN_GAS):
            assert self.c.spin(5, value=5 * ETHER) == 1

        current_round = self.c.get_current_round()
        assert current_round == 1

        player, block, bet, result, entropy, status = self.c.get_round(
            current_round)
        assert address(player) == tester.a0.encode('hex')
        assert block == 0
        assert bet == 5
        assert result == 0
        assert entropy == 0
        assert status == 1  # spinning

        assert self.c.get_stats() == [1, 5, 0]
コード例 #11
0
 def test_init(self):
     assert self.s.block.get_code(self.c.address) != ''
     assert address(self.s.block.get_storage_data(self.c.address, 0)) == tester.a0.encode('hex')
     assert self.s.block.get_storage_data(self.c.address, 1) == 1