Skip to content

Commit

Permalink
Merge pull request #337 from coinbase/christopher.gerber/feat/wallet-…
Browse files Browse the repository at this point in the history
…address-invoke-contract-input-validation

feat: wallet address invoke contract input validation
  • Loading branch information
stat authored Dec 10, 2024
2 parents 102e6c1 + 7deb989 commit 9cba1ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Added

- Wallet address contract invocation input validation for payable contracts.

### [0.11.2] - 2024-12-04

### Added
Expand Down
6 changes: 6 additions & 0 deletions src/coinbase/address/wallet_address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ export class WalletAddress extends Address {
throw new Error("Cannot invoke contract from address without private key loaded");
}

if (amount && !assetId) {
throw new ArgumentError(
"Asset ID is required for contract ivocation if an amount is provided",
);
}

let atomicAmount: string | undefined;

if (assetId && amount) {
Expand Down
16 changes: 16 additions & 0 deletions src/tests/wallet_address_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,22 @@ describe("WalletAddress", () => {
});
});

describe("when it is fails to invoke a payable contract method", () => {
let amount = new Decimal("1000");

it("throws an error for invalid input", async () => {
await expect(
walletAddress.invokeContract({
abi: MINT_NFT_ABI,
args: MINT_NFT_ARGS,
method: VALID_CONTRACT_INVOCATION_MODEL.method,
contractAddress: VALID_CONTRACT_INVOCATION_MODEL.contract_address,
amount,
}),
).rejects.toThrow(Error);
});
});

describe("when no key is loaded", () => {
beforeEach(() => {
walletAddress = new WalletAddress(addressModel);
Expand Down

0 comments on commit 9cba1ab

Please sign in to comment.