Skip to content

Commit

Permalink
feat: add withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
Atlasoin committed Dec 30, 2024
1 parent 11acec5 commit 01143fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Pi.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ contract Pi is OVMClient, OwnableUpgradeable {
emit ResponseParsed(requestId, success, strPI);
}

function withdraw() external onlyOwner {
payable(owner()).transfer(address(this).balance);
}

/**
* @dev Retrieves the response associated with the given request ID.
* @param requestId The ID of the request.
Expand Down
17 changes: 17 additions & 0 deletions test/Pi.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,21 @@ contract PiTest is Test {
string memory strPI = pi.getResponse("0x1234");
vm.assertEq(strPI, "3.14159");
}

function testWithdraw() public {
// Fund the contract
vm.deal(address(pi), 1 ether);

// Ensure only owner can withdraw
vm.expectRevert();
pi.withdraw();

// Check withdrawal by owner
uint256 aliceBalanceBefore = alice.balance;
vm.prank(alice);
pi.withdraw();

assertEq(address(pi).balance, 0);
assertEq(alice.balance, aliceBalanceBefore + 1 ether);
}
}

0 comments on commit 01143fb

Please sign in to comment.