diff --git a/axie-utils/axie_utils/claims.py b/axie-utils/axie_utils/claims.py index 199659b..d45d25e 100644 --- a/axie-utils/axie_utils/claims.py +++ b/axie-utils/axie_utils/claims.py @@ -41,29 +41,29 @@ def localize_date(self, date_utc): def humanize_date(self, date): local_date = self.localize_date(date) return local_date.strftime("%m/%d/%Y, %H:%M") - + def has_unclaimed_slp(self): - url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1" + url = f"http://game-api-pre.skymavis.com/v1/players/{self.account}/items/1" try: response = self.request.get(url, headers={"User-Agent": self.user_agent}) except RetryError: logging.critical(f"Important: Failed to check if there is unclaimed SLP for acc {self.acc_name} " - f"({self.account.replace('0x','ronin:')})") + f"({self.account.replace('0x', 'ronin:')})") return None if 200 <= response.status_code <= 299: data = response.json() - last_claimed = datetime.utcfromtimestamp(data['last_claimed_item_at']) + last_claimed = datetime.utcfromtimestamp(data['lastClaimedItemAt']) next_claim_date = last_claimed + timedelta(days=14) utcnow = datetime.utcnow() if utcnow < next_claim_date and not self.force: - logging.critical(f"Important: This account will be claimable again on {self.humanize_date(next_claim_date)}.") + logging.critical( + f"Important: This account will be claimable again on {self.humanize_date(next_claim_date)}.") return None elif self.force: - logging.info('Skipping check of dates, --force option was selected') - wallet_total = check_balance(self.account) - in_game_total = int(data['total']) - if in_game_total > wallet_total: - return in_game_total - wallet_total + logging.info('Important: Skipping check of dates, --force option was selected') + claimable_total = int(data['rawClaimableTotal']) + if claimable_total > 0: + return claimable_total return None async def async_execute(self): @@ -83,7 +83,7 @@ async def async_execute(self): "User-Agent": self.user_agent, "authorization": f"Bearer {jwt}" } - url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1/claim" + url = "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim" try: response = self.request.post(url, headers=headers, json="") except RetryError as e: @@ -91,10 +91,10 @@ async def async_execute(self): f"({self.account.replace('0x', 'ronin:')}). Error {e}") return if 200 <= response.status_code <= 299: - signature = response.json()["blockchain_related"].get("signature") + signature = response.json()["blockchainRelated"].get("signature") if not signature or not signature["signature"]: logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature " - "in blockchain_related") + "in blockchainRelated") return else: logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) " @@ -161,7 +161,7 @@ def execute(self): "User-Agent": self.user_agent, "authorization": f"Bearer {jwt}" } - url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1/claim" + url = "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim" try: response = self.request.post(url, headers=headers, json="") except RetryError as e: @@ -169,10 +169,10 @@ def execute(self): f"({self.account.replace('0x', 'ronin:')}). Error {e}") return if 200 <= response.status_code <= 299: - signature = response.json()["blockchain_related"].get("signature") + signature = response.json()["blockchainRelated"].get("signature") if not signature or not signature["signature"]: logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature " - "in blockchain_related") + "in blockchainRelated") return else: logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) " @@ -248,10 +248,9 @@ def localize_date(self, date_utc): def humanize_date(self, date): local_date = self.localize_date(date) return local_date.strftime("%m/%d/%Y, %H:%M") - - + def has_unclaimed_slp(self): - url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1" + url = f"http://game-api-pre.skymavis.com/v1/players/{self.account}/items/1" try: response = self.request.get(url, headers={"User-Agent": self.user_agent}) except RetryError: @@ -260,7 +259,7 @@ def has_unclaimed_slp(self): return None if 200 <= response.status_code <= 299: data = response.json() - last_claimed = datetime.utcfromtimestamp(data['last_claimed_item_at']) + last_claimed = datetime.utcfromtimestamp(data['lastClaimedItemAt']) next_claim_date = last_claimed + timedelta(days=14) utcnow = datetime.utcnow() if utcnow < next_claim_date and not self.force: @@ -268,10 +267,9 @@ def has_unclaimed_slp(self): return None elif self.force: logging.info('Important: Skipping check of dates, --force option was selected') - wallet_total = check_balance(self.account) - in_game_total = int(data['total']) - if in_game_total > wallet_total: - return in_game_total - wallet_total + claimable_total = int(data['rawClaimableTotal']) + if claimable_total > 0: + return claimable_total return None async def async_execute(self): @@ -291,7 +289,7 @@ async def async_execute(self): "User-Agent": self.user_agent, "authorization": f"Bearer {jwt}" } - url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1/claim" + url = "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim" try: response = self.request.post(url, headers=headers, json="") except RetryError as e: @@ -299,10 +297,10 @@ async def async_execute(self): f"({self.account.replace('0x', 'ronin:')}). Error {e}") return if 200 <= response.status_code <= 299: - signature = response.json()["blockchain_related"].get("signature") + signature = response.json()["blockchainRelated"].get("signature") if not signature or not signature["signature"]: logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature " - "in blockchain_related") + "in blockchainRelated") return else: logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) " @@ -383,7 +381,7 @@ def execute(self): "User-Agent": self.user_agent, "authorization": f"Bearer {jwt}" } - url = f"https://game-api.skymavis.com/game-api/clients/{self.account}/items/1/claim" + url = "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim" try: response = self.request.post(url, headers=headers, json="") except RetryError as e: @@ -391,10 +389,10 @@ def execute(self): f"({self.account.replace('0x', 'ronin:')}). Error {e}") return if 200 <= response.status_code <= 299: - signature = response.json()["blockchain_related"].get("signature") + signature = response.json()["blockchainRelated"].get("signature") if not signature or not signature["signature"]: logging.critical(f"Important: Account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) had no signature " - "in blockchain_related") + "in blockchainRelated") return else: logging.info(f"Important: Claim for account {self.acc_name} ({self.account.replace('0x', 'ronin:')}) " diff --git a/axie-utils/tests/test_claims.py b/axie-utils/tests/test_claims.py index 523318d..85bc585 100644 --- a/axie-utils/tests/test_claims.py +++ b/axie-utils/tests/test_claims.py @@ -30,7 +30,7 @@ def test_claim_init(mocked_provider, mocked_checksum, mocked_contract): assert c.private_key == "bar" assert c.account == "0xfoo" assert c.acc_name == "test_acc" - assert c.force == False + assert c.force is False @patch("web3.eth.Eth.contract") @@ -50,27 +50,25 @@ def test_claim_init_force(mocked_provider, mocked_checksum, mocked_contract): assert c.private_key == "bar" assert c.account == "0xfoo" assert c.acc_name == "test_acc" - assert c.force == True + assert c.force is True -@patch("axie_utils.claims.check_balance", return_value=10) @patch("web3.eth.Eth.contract") @patch("web3.Web3.toChecksumAddress", return_value="checksum") @patch("web3.Web3.HTTPProvider", return_value="provider") -def test_has_unclaimed_slp(mocked_provider, mocked_checksum, mocked_contract, mocked_check): +def test_has_unclaimed_slp(mocked_provider, mocked_checksum, mocked_contract): last_claimed_date = datetime.utcnow() - timedelta(days=15) with requests_mock.Mocker() as req_mocker: - req_mocker.get("https://game-api.skymavis.com/game-api/clients/0xfoo/items/1", + req_mocker.get("http://game-api-pre.skymavis.com/v1/players/0xfoo/items/1", json={"total": 12, - "last_claimed_item_at": last_claimed_date.timestamp(), - "claimable_total": 0}) + "lastClaimedItemAt": last_claimed_date.timestamp(), + "rawClaimableTotal": 2}) with patch.object(builtins, "open", mock_open(read_data='{"foo": "bar"}')): c = Claim(account="ronin:foo", private_key="0xbar", acc_name="test_acc", force=False) unclaimed = c.has_unclaimed_slp() assert unclaimed == 2 - mocked_check.assert_called_with("0xfoo") mocked_provider.assert_called_with( RONIN_PROVIDER, request_kwargs={"headers": {"content-type": "application/json", "user-agent": USER_AGENT}} @@ -79,17 +77,16 @@ def test_has_unclaimed_slp(mocked_provider, mocked_checksum, mocked_contract, mo mocked_contract.assert_called() -@patch("axie_utils.claims.check_balance", return_value=10) @patch("web3.eth.Eth.contract") @patch("web3.Web3.toChecksumAddress", return_value="checksum") @patch("web3.Web3.HTTPProvider", return_value="provider") -def test_has_unclaimed_failed_date(mocked_provider, mocked_checksum, mocked_contract, mocked_check): +def test_has_unclaimed_failed_date(mocked_provider, mocked_checksum, mocked_contract): last_claimed_date = datetime.utcnow() - timedelta(days=13) + timedelta(minutes=1) with requests_mock.Mocker() as req_mocker: - req_mocker.get("https://game-api.skymavis.com/game-api/clients/0xfoo/items/1", + req_mocker.get("http://game-api-pre.skymavis.com/v1/players/0xfoo/items/1", json={"total": 12, - "last_claimed_item_at": last_claimed_date.timestamp(), - "claimable_total": 0}) + "lastClaimedItemAt": last_claimed_date.timestamp(), + "rawClaimableTotal": 2}) with patch.object(builtins, "open", mock_open(read_data='{"foo": "bar"}')): @@ -101,21 +98,19 @@ def test_has_unclaimed_failed_date(mocked_provider, mocked_checksum, mocked_cont request_kwargs={"headers": {"content-type": "application/json", "user-agent": USER_AGENT}} ) mocked_checksum.assert_called_with(SLP_CONTRACT) - mocked_check.assert_not_called() mocked_contract.assert_called() -@patch("axie_utils.claims.check_balance", return_value=10) @patch("web3.eth.Eth.contract") @patch("web3.Web3.toChecksumAddress", return_value="checksum") @patch("web3.Web3.HTTPProvider", return_value="provider") -def test_has_unclaimed_date_force(mocked_provider, mocked_checksum, mocked_contract, mocked_check): +def test_has_unclaimed_date_force(mocked_provider, mocked_checksum, mocked_contract): last_claimed_date = datetime.utcnow() - timedelta(days=14) + timedelta(minutes=1) with requests_mock.Mocker() as req_mocker: - req_mocker.get("https://game-api.skymavis.com/game-api/clients/0xfoo/items/1", + req_mocker.get("http://game-api-pre.skymavis.com/v1/players/0xfoo/items/1", json={"total": 12, - "last_claimed_item_at": last_claimed_date.timestamp(), - "claimable_total": 0}) + "lastClaimedItemAt": last_claimed_date.timestamp(), + "rawClaimableTotal": 2}) with patch.object(builtins, "open", mock_open(read_data='{"foo": "bar"}')): @@ -127,7 +122,6 @@ def test_has_unclaimed_date_force(mocked_provider, mocked_checksum, mocked_contr request_kwargs={"headers": {"content-type": "application/json", "user-agent": USER_AGENT}} ) mocked_checksum.assert_called_with(SLP_CONTRACT) - mocked_check.assert_called() mocked_contract.assert_called() @@ -136,7 +130,7 @@ def test_has_unclaimed_date_force(mocked_provider, mocked_checksum, mocked_contr @patch("web3.Web3.HTTPProvider", return_value="provider") def test_has_unclaimed_slp_failed_req(mocked_provider, mocked_checksum, mocked_contract): with requests_mock.Mocker() as req_mocker: - req_mocker.get("https://game-api.skymavis.com/game-api/clients/0xfoo/items/1", + req_mocker.get("http://game-api-pre.skymavis.com/v1/players/0xfoo/items/1", status_code=500) with patch.object(builtins, "open", @@ -359,9 +353,9 @@ def test_claim_execution(mocked_provider, mock_open(read_data='{"foo": "bar"}')): with requests_mock.Mocker() as req_mocker: req_mocker.post( - "https://game-api.skymavis.com/game-api/clients/0xfoo/items/1/claim", + "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim", json={ - "blockchain_related": { + "blockchainRelated": { "signature": { "amount": "456", "timestamp": str(int(datetime.now().timestamp())), @@ -420,9 +414,9 @@ def test_execution_failed_get_blockchain(mocked_provider, mock_open(read_data='{"foo": "bar"}')): with requests_mock.Mocker() as req_mocker: req_mocker.post( - "https://game-api.skymavis.com/game-api/clients/0xfoo/items/1/claim", + "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim", json={ - "blockchain_related": { + "blockchainRelated": { "signature": { "amount": "", "timestamp": 0, @@ -474,25 +468,24 @@ def test_trezor_claim_init(mocked_provider, mocked_checksum, mocked_contract, mo assert c.acc_name == "test_acc" -@patch("axie_utils.claims.check_balance", return_value=10) @patch("axie_utils.graphql.parse_path", return_value="parsed_path") @patch("web3.eth.Eth.contract") @patch("web3.Web3.toChecksumAddress", return_value="checksum") @patch("web3.Web3.HTTPProvider", return_value="provider") -def test_has_unclaimed_slp_trezor(mocked_provider, mocked_checksum, mocked_contract, mocked_parse, mocked_check): +def test_has_unclaimed_slp_trezor(mocked_provider, mocked_checksum, mocked_contract, mocked_parse): last_claimed_date = datetime.now() - timedelta(days=15) with requests_mock.Mocker() as req_mocker: - req_mocker.get("https://game-api.skymavis.com/game-api/clients/0xfoo/items/1", + req_mocker.get("http://game-api-pre.skymavis.com/v1/players/0xfoo/items/1", json={"total": 12, - "last_claimed_item_at": round(last_claimed_date.timestamp()), - "claimable_total": 0}) + "lastClaimedItemAt": round(last_claimed_date.timestamp()), + "rawClaimableTotal": 2}) with patch.object(builtins, "open", mock_open(read_data='SLP_ABI')): - c = TrezorClaim(account="ronin:foo", acc_name="test_acc", bip_path="m/44'/60'/0'/0/0", client="client", force=False) + c = TrezorClaim(account="ronin:foo", acc_name="test_acc", bip_path="m/44'/60'/0'/0/0", client="client", + force=False) unclaimed = c.has_unclaimed_slp() assert unclaimed == 2 - mocked_check.assert_called_with("0xfoo") mocked_parse.assert_called_with("m/44'/60'/0'/0/0") mocked_provider.assert_called_with( RONIN_PROVIDER, @@ -508,7 +501,7 @@ def test_has_unclaimed_slp_trezor(mocked_provider, mocked_checksum, mocked_contr @patch("web3.Web3.HTTPProvider", return_value="provider") def test_has_unclaimed_slp_failed_req_trezor(mocked_provider, mocked_checksum, mocked_contract, mocked_parse): with requests_mock.Mocker() as req_mocker: - req_mocker.get("https://game-api.skymavis.com/game-api/clients/0xfoo/items/1", + req_mocker.get("http://game-api-pre.skymavis.com/v1/players/0xfoo/items/1", status_code=500) with patch.object(builtins, "open", @@ -752,9 +745,9 @@ async def test_claim_async_execute_trezor(mocked_provider, mock_open(read_data='SLP_ABI')): with requests_mock.Mocker() as req_mocker: req_mocker.post( - "https://game-api.skymavis.com/game-api/clients/0xfoo/items/1/claim", + "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim", json={ - "blockchain_related": { + "blockchainRelated": { "signature": { "amount": "456", "timestamp": str(int(datetime.now().timestamp())), @@ -824,9 +817,9 @@ async def test_async_execute_failed_get_blockchain_trezor(mocked_provider, mock_open(read_data='SLP_ABI')): with requests_mock.Mocker() as req_mocker: req_mocker.post( - "https://game-api.skymavis.com/game-api/clients/0xfoo/items/1/claim", + "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim", json={ - "blockchain_related": { + "blockchainRelated": { "signature": { "amount": "", "timestamp": 0, @@ -895,9 +888,9 @@ def test_claim_execute_trezor(mocked_provider, mock_open(read_data='SLP_ABI')): with requests_mock.Mocker() as req_mocker: req_mocker.post( - "https://game-api.skymavis.com/game-api/clients/0xfoo/items/1/claim", + "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim", json={ - "blockchain_related": { + "blockchainRelated": { "signature": { "amount": "456", "timestamp": str(int(datetime.now().timestamp())), @@ -966,9 +959,9 @@ def test_execute_failed_get_blockchain_trezor(mocked_provider, mock_open(read_data='SLP_ABI')): with requests_mock.Mocker() as req_mocker: req_mocker.post( - "https://game-api.skymavis.com/game-api/clients/0xfoo/items/1/claim", + "http://game-api-pre.skymavis.com/v1/players/me/items/1/claim", json={ - "blockchain_related": { + "blockchainRelated": { "signature": { "amount": "", "timestamp": 0,