Skip to content

Commit

Permalink
[OCT-1822] apitest: potential fix for nonce-too-low problem (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek authored Jan 14, 2025
2 parents 1f12360 + 13a2537 commit 7486963
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backend/app/infrastructure/contracts/erc20.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def glm_fund(self, to_address, nonce):
return self.w3.eth.send_raw_transaction(signed_tx.rawTransaction)

def transfer(self, sender, receiver: str, amount: int):
nonce = self.w3.eth.get_transaction_count(sender.address)
nonce = self.w3.eth.get_transaction_count(sender.address, "pending")
transaction = self.contract.functions.transfer(
receiver, amount
).build_transaction({"from": sender.address, "nonce": nonce})
Expand All @@ -26,7 +26,7 @@ def approve(self, owner, benefactor, wad: int):
print("owner address: ", owner.address)
print("owner key: ", owner.key)
print("benefactor of lock: ", benefactor)
nonce = self.w3.eth.get_transaction_count(owner.address)
nonce = self.w3.eth.get_transaction_count(owner.address, "pending")
transaction = self.contract.functions.approve(
benefactor, wad
).build_transaction({"from": owner.address, "nonce": nonce})
Expand Down
7 changes: 5 additions & 2 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,11 @@ def snapshot_status(self, epoch):
return json.loads(rv.text), rv.status_code

def pending_snapshot(self):
rv = self._flask_client.post("/snapshots/pending").text
return json.loads(rv)
rv = self._flask_client.post("/snapshots/pending")
current_app.logger.debug(
f"Request to /snapshots/pending [{rv.status_code}] returned text {rv.text}"
)
return json.loads(rv.text)

def pending_snapshot_simulate(self):
rv = self._flask_client.get("/snapshots/pending/simulate")
Expand Down
14 changes: 0 additions & 14 deletions backend/v2/glms/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ class AddressKey(Protocol):


class GLMContracts(SmartContract):
# def glm_fund(self, to_address, nonce):
# transaction = self.contract.functions.transfer(
# to_address, app.config["GLM_WITHDRAWAL_AMOUNT"]
# ).build_transaction({"from": app.config["GLM_SENDER_ADDRESS"], "nonce": nonce})
# signed_tx = self.w3.eth.account.sign_transaction(
# transaction, app.config["GLM_SENDER_PRIVATE_KEY"]
# )
# return self.w3.eth.send_raw_transaction(signed_tx.rawTransaction)

# def transfer(self, sender, receiver: str, amount: int):
# async def transfer(self, sender_address: str, receiver: str, amount: int):
async def transfer(
self, sender: AddressKey, receiver_address: str, amount: int
) -> None:
Expand All @@ -42,9 +31,6 @@ async def approve(self, owner: AddressKey, benefactor_address, wad: int):
signed_tx = self.w3.eth.account.sign_transaction(transaction, owner.key)
return self.w3.eth.send_raw_transaction(signed_tx.rawTransaction)

# def balance_of(self, owner: str) -> int:
# return self.contract.functions.balanceOf(owner).call()


ERC20_ABI = [
{
Expand Down

0 comments on commit 7486963

Please sign in to comment.