@reality.eth/contracts 4.0.0-rc.6 → 4.0.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,8 +7,6 @@ import {IBalanceHolder} from "./IBalanceHolder.sol";
|
|
|
7
7
|
contract BalanceHolder is IBalanceHolder {
|
|
8
8
|
mapping(address => uint256) public balanceOf;
|
|
9
9
|
|
|
10
|
-
event LogWithdraw(address indexed user, uint256 amount);
|
|
11
|
-
|
|
12
10
|
function withdraw() public {
|
|
13
11
|
uint256 bal = balanceOf[msg.sender];
|
|
14
12
|
balanceOf[msg.sender] = 0;
|
package/package.json
CHANGED
package/tests/python/test.py
CHANGED
|
@@ -2713,8 +2713,102 @@ class TestRealitio(TestCase):
|
|
|
2713
2713
|
with self.assertRaises(TransactionFailed):
|
|
2714
2714
|
self.rc0.functions.isHistoryOfUnfinalizedQuestionValid(self.question_id, st['hash'], st['addr'], st['bond'], st['answer']).transact()
|
|
2715
2715
|
|
|
2716
|
+
|
|
2717
|
+
def _setupEarlyAnsweredQuestion(self, questioner, answerer):
|
|
2718
|
+
|
|
2719
|
+
# We'll set up a question that finalizes before the freeze date to check we can still get its result after the freeze
|
|
2720
|
+
txid = self.rc0.functions.askQuestionERC20(
|
|
2721
|
+
0,
|
|
2722
|
+
"my early question",
|
|
2723
|
+
self.arb0.address,
|
|
2724
|
+
30,
|
|
2725
|
+
0,
|
|
2726
|
+
0
|
|
2727
|
+
,1100
|
|
2728
|
+
).transact(self._txargs(sender=questioner))
|
|
2729
|
+
early_question_id = calculate_question_id(self.rc0.address, 0, "my early question", self.arb0.address, 30, 0, 0, questioner, 0)
|
|
2730
|
+
st = None
|
|
2731
|
+
st = self.submitAnswerReturnUpdatedState( st, early_question_id, 1001, 0, 200, answerer)
|
|
2732
|
+
st = self.submitAnswerReturnUpdatedState( st, early_question_id, 1001, 200, 400, answerer)
|
|
2733
|
+
|
|
2734
|
+
fee = self.rc0.functions.arbitrator_question_fees(self.arb0.address).call()
|
|
2735
|
+
|
|
2736
|
+
expected_winnings = 1100+400+subfee(200)-fee
|
|
2737
|
+
|
|
2738
|
+
return early_question_id, st, expected_winnings
|
|
2739
|
+
|
|
2740
|
+
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
2741
|
+
def test_frozen_claim_and_disabled(self):
|
|
2742
|
+
|
|
2743
|
+
if not IS_FREEZE_SUPPORTED:
|
|
2744
|
+
print("Skipping test_frozen, not supported by this version")
|
|
2745
|
+
return
|
|
2746
|
+
|
|
2747
|
+
if ERC20:
|
|
2748
|
+
self._issueTokens(self.web3.eth.accounts[0], 1000000, 1000000)
|
|
2749
|
+
self._issueTokens(self.web3.eth.accounts[3], 1000000, 1000000)
|
|
2750
|
+
|
|
2751
|
+
early_question_id, st, expected_winnings = self._setupEarlyAnsweredQuestion(self.web3.eth.accounts[0], self.web3.eth.accounts[3])
|
|
2752
|
+
self._advance_clock(40)
|
|
2753
|
+
self.rc0.functions.setFreezeTimestamp(self._block_timestamp()).transact(self._txargs())
|
|
2754
|
+
|
|
2755
|
+
txid = self.rc0.functions.claimMultipleAndWithdrawBalance([early_question_id], [len(st['hash'])], st['hash'], st['addr'], st['bond'], st['answer']).transact(self._txargs())
|
|
2756
|
+
with self.assertRaises(TransactionFailed):
|
|
2757
|
+
self.raiseOnZeroStatus(txid)
|
|
2758
|
+
|
|
2759
|
+
|
|
2760
|
+
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
2761
|
+
def test_frozen_withdraw(self):
|
|
2762
|
+
|
|
2763
|
+
if not IS_FREEZE_SUPPORTED:
|
|
2764
|
+
print("Skipping test_frozen, not supported by this version")
|
|
2765
|
+
return
|
|
2766
|
+
|
|
2767
|
+
if ERC20:
|
|
2768
|
+
self._issueTokens(self.web3.eth.accounts[0], 1000000, 1000000)
|
|
2769
|
+
self._issueTokens(self.web3.eth.accounts[3], 1000000, 1000000)
|
|
2770
|
+
|
|
2771
|
+
txid = self.rc0.functions.withdraw().transact(self._txargs(sender=self.web3.eth.accounts[3]))
|
|
2772
|
+
self.assertEqual(self.rc0.functions.balanceOf(self.web3.eth.accounts[3]).call(), 0)
|
|
2773
|
+
|
|
2774
|
+
early_question_id, st, expected_winnings = self._setupEarlyAnsweredQuestion(self.web3.eth.accounts[0], self.web3.eth.accounts[3])
|
|
2775
|
+
self._advance_clock(40)
|
|
2776
|
+
|
|
2777
|
+
txid = self.rc0.functions.claimWinnings(early_question_id, st['hash'], st['addr'], st['bond'], st['answer']).transact(self._txargs())
|
|
2778
|
+
self.raiseOnZeroStatus(txid)
|
|
2779
|
+
self.assertEqual(self.rc0.functions.balanceOf(self.web3.eth.accounts[3]).call(), expected_winnings)
|
|
2780
|
+
|
|
2781
|
+
self.rc0.functions.setFreezeTimestamp(self._block_timestamp()).transact(self._txargs())
|
|
2782
|
+
|
|
2783
|
+
txid = self.rc0.functions.withdraw().transact(self._txargs(sender=self.web3.eth.accounts[3]))
|
|
2784
|
+
with self.assertRaises(TransactionFailed):
|
|
2785
|
+
self.raiseOnZeroStatus(txid)
|
|
2786
|
+
|
|
2787
|
+
self.assertEqual(self.rc0.functions.balanceOf(self.web3.eth.accounts[3]).call(), expected_winnings)
|
|
2788
|
+
|
|
2789
|
+
|
|
2790
|
+
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
2791
|
+
def test_frozen_claim_winnings(self):
|
|
2792
|
+
|
|
2793
|
+
if not IS_FREEZE_SUPPORTED:
|
|
2794
|
+
print("Skipping test_frozen, not supported by this version")
|
|
2795
|
+
return
|
|
2796
|
+
|
|
2797
|
+
if ERC20:
|
|
2798
|
+
self._issueTokens(self.web3.eth.accounts[0], 1000000, 1000000)
|
|
2799
|
+
self._issueTokens(self.web3.eth.accounts[3], 1000000, 1000000)
|
|
2800
|
+
|
|
2801
|
+
early_question_id, st, expected_winnings = self._setupEarlyAnsweredQuestion(self.web3.eth.accounts[0], self.web3.eth.accounts[3])
|
|
2802
|
+
self._advance_clock(40)
|
|
2803
|
+
|
|
2804
|
+
self.rc0.functions.setFreezeTimestamp(self._block_timestamp()).transact(self._txargs())
|
|
2805
|
+
|
|
2806
|
+
txid = self.rc0.functions.claimWinnings(early_question_id, st['hash'], st['addr'], st['bond'], st['answer']).transact(self._txargs())
|
|
2807
|
+
with self.assertRaises(TransactionFailed):
|
|
2808
|
+
self.raiseOnZeroStatus(txid)
|
|
2809
|
+
|
|
2716
2810
|
@unittest.skipIf(WORKING_ONLY, "Not under construction")
|
|
2717
|
-
def
|
|
2811
|
+
def test_frozen_result(self):
|
|
2718
2812
|
|
|
2719
2813
|
if not IS_FREEZE_SUPPORTED:
|
|
2720
2814
|
print("Skipping test_frozen, not supported by this version")
|
|
@@ -2730,26 +2824,15 @@ class TestRealitio(TestCase):
|
|
|
2730
2824
|
self._issueTokens(k3, 1000000, 1000000)
|
|
2731
2825
|
self._issueTokens(k4, 1000000, 1000000)
|
|
2732
2826
|
|
|
2733
|
-
|
|
2734
|
-
txid = self.rc0.functions.askQuestionERC20(
|
|
2735
|
-
0,
|
|
2736
|
-
"my early question",
|
|
2737
|
-
self.arb0.address,
|
|
2738
|
-
30,
|
|
2739
|
-
0,
|
|
2740
|
-
0
|
|
2741
|
-
,1100
|
|
2742
|
-
).transact(self._txargs())
|
|
2743
|
-
early_question_id = calculate_question_id(self.rc0.address, 0, "my early question", self.arb0.address, 30, 0, 0, self.web3.eth.accounts[0], 0)
|
|
2744
|
-
st = None
|
|
2745
|
-
st = self.submitAnswerReturnUpdatedState( st, early_question_id, 1001, 0, 200, k3)
|
|
2746
|
-
st = self.submitAnswerReturnUpdatedState( st, early_question_id, 1001, 200, 400, k3)
|
|
2827
|
+
early_question_id, st, expected_winnings = self._setupEarlyAnsweredQuestion(k0, k3)
|
|
2747
2828
|
|
|
2748
2829
|
self.assertFalse(self.rc0.functions.isFinalized(early_question_id).call())
|
|
2749
2830
|
# Can't get result as not finalized
|
|
2750
2831
|
with self.assertRaises(TransactionFailed):
|
|
2751
2832
|
self.assertEqual(self.rc0.functions.resultFor(early_question_id).call(), to_answer_for_contract(1001))
|
|
2752
2833
|
|
|
2834
|
+
self.rc0.functions.claimMultipleAndWithdrawBalance([self.question_id], [len(st['hash'])], st['hash'], st['addr'], st['bond'], st['answer']).transact(self._txargs(sender=k5))
|
|
2835
|
+
|
|
2753
2836
|
self._advance_clock(40)
|
|
2754
2837
|
self.assertTrue(self.rc0.functions.isFinalized(early_question_id).call())
|
|
2755
2838
|
self.assertEqual(self.rc0.functions.resultFor(early_question_id).call(), to_answer_for_contract(1001))
|