diff --git a/.prettierrc b/.prettierrc index 07a2cea..ac0fa89 100644 --- a/.prettierrc +++ b/.prettierrc @@ -9,4 +9,3 @@ "arrowParens": "always", "endOfLine": "lf" } - diff --git a/docs/test-specifications/crypto-service/AccountAllowanceApproveTransaction.md b/docs/test-specifications/crypto-service/AccountAllowanceApproveTransaction.md new file mode 100644 index 0000000..7f8b81d --- /dev/null +++ b/docs/test-specifications/crypto-service/AccountAllowanceApproveTransaction.md @@ -0,0 +1,369 @@ +# AccountAllowanceApproveTransaction - Test specification + +## Description: +This test specification for AccountAllowanceApproveTransaction is to be one of many for testing the functionality of the Hedera SDKs. The SDK under test will use the language specific JSON-RPC server return responses back to the test driver. + +## Design: +Each test within the test specification is linked to one of the functions within AccountAllowanceApproveTransaction. Each function is tested with a mix of boundaries. The inputs for each test are a range of valid, minimum, maximum, negative and invalid values for the method. The expected response of a passed test can be a correct error response code or seen as the result of node queries. A successful transaction (the transaction reached consensus and was applied to state) can be determined by getting a `TransactionReceipt` or `TransactionRecord`, or can be determined by using queries such as `AccountInfoQuery` or `AccountBalanceQuery` and investigating for the required changes (creations, updates, etc.). The mirror node can also be used to determine if a transaction was successful via its rest API. Error codes are obtained from the response code proto files. + +**Transaction properties:** + +https://docs.hedera.com/hedera/sdks-and-apis/sdks/accounts-and-hbar/create-an-account + +**CryptoApproveAllowance protobufs:** + +https://github.com/hashgraph/hedera-protobufs/blob/main/services/crypto_approve_allowance.proto + +**Response codes:** + +https://github.com/hashgraph/hedera-protobufs/blob/main/services/response_code.proto + +**Mirror Node APIs:** + +https://docs.hedera.com/hedera/sdks-and-apis/rest-api + +## JSON-RPC API Endpoint Documentation + +### Method Name + +`approveAllowance` + +### Input Parameters + +| Parameter Name | Type | Required/Optional | Description/Notes | +|-------------------------|--------------------------------------------------|-------------------|----------------------------| +| allowances | list<[json object](allowances.md)> | required | The allowance information. | +| commonTransactionParams | [json object](../commonTransactionParameters.md) | optional | | + +### Output Parameters + +| Parameter Name | Type | Description/Notes | +|----------------|--------|-------------------------------------------------------------------------------------------------| +| status | string | The status of the submitted `AccountAllowanceApproveTransaction` (from a `TransactionReceipt`). | + +### Additional Notes + +The tests contained in this specification will assume that valid owner and spender accounts were already successfully created. will denote the ID of the owner account and will denote the private key of the account as a DER-encoded hex string. will the denote the ID of the spender account, and will denote the private key of the account as a DER-encoded hex string. For tests that require tokens, they will assume a valid token has already been created. For simplicity, the treasury account of the token will be the owner account. If the token is fungible, the initial and max supply will be 1000. If the token is non-fungible, three NFTs should be minted. The token will also be associated with the spender account. will denote the ID of this token. , , and will denote the serial numbers of the minted NFTs. For `DeleteNftAllowanceAllSerials`, the minted NFTs should already be allowanced to the sender account as well. + +## Function Tests + +### **ApproveHbarAllowance:** + +- Approves an allowance of Hbar to an account. + +| Test no | Name | Input | Expected response | Implemented (Y/N) | +|---------|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|-------------------| +| 1 | Approves an hbar allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the allowance. | Y | +| 2 | Approves an hbar allowance to a spender account from an owner account that doesn't exist | allowances=[{ownerAccountId="123.456.789", spenderAccountId=, hbar.amount="10"}] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | Y | +| 3 | Approves an hbar allowance to a spender account from an empty owner account | allowances=[{ownerAccountId="", spenderAccountId=, hbar.amount="10"}] | The allowance approval fails with an SDK internal error. | Y | +| 4 | Approves an hbar allowance to a spender account from a deleted owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | Y | +| 5 | Approves an hbar allowance to a spender account that doesn't exist from an owner account | allowances=[{ownerAccountId=, spenderAccountId="123.456.789", hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | Y | +| 6 | Approves an hbar allowance to an empty spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId="", hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | Y | +| 7 | Approves an hbar allowance to a deleted spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | Y | +| 8 | Approves a 0 hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="0"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has no allowance. | Y | +| 9 | Approves a -1 hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="-1"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | Y | +| 10 | Approves a 9,223,372,036,854,775,806 (int64 max - 1) hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="9223372036854775806"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has an allowance of 9,223,372,036,854,775,806 hbar. | Y | +| 11 | Approves a 9,223,372,036,854,775,807 (int64 max) hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="9223372036854775807"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has an allowance of 9,223,372,036,854,775,807 hbar. | Y | +| 12 | Approves a -9,223,372,036,854,775,808 (int64 min) hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="-9223372036854775808"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | Y | +| 13 | Approves a -9,223,372,036,854,775,807 (int64 min + 1) hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="-9223372036854775807"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | Y | +| 14 | Approves an hbar allowance to an account from the same account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SPENDER_ACCOUNT_SAME_AS_OWNER response code from the network. | Y | + +#### JSON Request Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "method": "approveAllowance", + "params": { + "allowances": [ + { + "ownerAccountId": "0.0.53232", + "spenderAccountId": "0.0.8532", + "hbar": { + "amount": "100" + } + } + ], + "commonTransactionParams": { + "signers": [ + "3030020100300706052b8104000a04220420e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" + ] + } + } +} +``` + +#### JSON Response Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "result": { + "status": "SUCCESS" + } +} +``` + +### **ApproveTokenAllowance:** + +- Approves an allowance of a token to an account. + +| Test no | Name | Input | Expected response | Implemented (Y/N) | +|---------|------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|-------------------| +| 1 | Approves a token allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the allowance. | Y | +| 2 | Approves a token allowance to a spender account from an owner account that doesn't exist | allowances=[{ownerAccountId="123.456.789", spenderAccountId=, token.tokenId=, token.amount="10"}] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | Y | +| 3 | Approves a token allowance to a spender account from an empty owner account | allowances=[{ownerAccountId="", spenderAccountId=, token.tokenId=, token.amount="10"}] | The allowance approval fails with an SDK internal error. | Y | +| 4 | Approves a token allowance to a spender account from a deleted owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_DELETED response code from the network. | Y | +| 5 | Approves a token allowance to a spender account that doesn't exist from an owner account | allowances=[{ownerAccountId=, spenderAccountId="123.456.789", token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | Y | +| 6 | Approves a token allowance to an empty spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId="", token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | Y | +| 7 | Approves a token allowance to a deleted spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_DELETED response code from the network. | Y | +| 8 | Approves a 0 token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="0"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has no allowance. | Y | +| 9 | Approves a -1 token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="-1"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | Y | +| 10 | Approves a 9,223,372,036,854,775,806 (int64 max - 1) token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="9223372036854775806"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has an allowance of 9,223,372,036,854,775,806 hbar. | Y | +| 11 | Approves a 9,223,372,036,854,775,807 (int64 max) token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="9223372036854775807"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has an allowance of 9,223,372,036,854,775,807 hbar. | Y | +| 12 | Approves a -9,223,372,036,854,775,808 (int64 min) token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="-9223372036854775808"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | Y | +| 13 | Approves a -9,223,372,036,854,775,807 (int64 min + 1) token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="-9223372036854775807"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | Y | +| 14 | Approves a token allowance to a spender account from an owner account with a token that doesn't exist | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId="123.456.789", token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_TOKEN_ID response code from the network. | Y | +| 15 | Approves a token allowance to a spender account from an owner account with an empty token ID | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId="", token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | Y | +| 16 | Approves a token allowance to a spender account from an owner account with a deleted token | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an TOKEN_WAS_DELETED response code from the network. | Y | +| 17 | Approves a token allowance to an account from the same account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SPENDER_ACCOUNT_SAME_AS_OWNER response code from the network. | Y | +| 18 | Approves a token allowance greater than the token's max supply to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10000"}], commonTransactionParams.signers=[] | The allowance approval fails with an AMOUNT_EXCEEDS_TOKEN_MAX_SUPPLY response code from the network. | Y | +| 19 | Approves a token allowance of an NFT to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an NFT_IN_FUNGIBLE_TOKEN_ALLOWANCES response code from the network. | Y | +| 20 | Approves a token allowance to a spender account from an owner account with a token frozen on the owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the allowance. | Y | +| 21 | Approves a token allowance to a spender account from an owner account with a token frozen on the spender account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the allowance. | Y | +| 22 | Approves a token allowance to a spender account from an owner account with a paused token | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the allowance. | Y | + +#### JSON Request Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "method": "approveAllowance", + "params": { + "allowances": [ + { + "ownerAccountId": "0.0.53232", + "spenderAccountId": "0.0.8532", + "token": { + "amount": "100", + "tokenId": "0.0.573298" + } + } + ], + "commonTransactionParams": { + "signers": [ + "3030020100300706052b8104000a04220420e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" + ] + } + } +} +``` + +#### JSON Response Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "result": { + "status": "SUCCESS" + } +} +``` + +### **ApproveTokenNftAllowance:** + +- Approves an allowance of an NFT to an account. + +| Test no | Name | Input | Expected response | Implemented (Y/N) | +|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|-------------------| +| 1 | Approves an NFT allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | +| 2 | Approves an NFT allowance to a spender account from an owner account that doesn't exist | allowances=[{ownerAccountId="123.456.789", spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | Y | +| 3 | Approves an NFT allowance to a spender account from an empty owner account | allowances=[{ownerAccountId="", spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}] | The allowance approval fails with an SDK internal error. | Y | +| 4 | Approves an NFT allowance to a spender account from a deleted owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_DELETED response code from the network. | Y | +| 5 | Approves an NFT allowance to a spender account that doesn't exist from an owner account | allowances=[{ownerAccountId=, spenderAccountId="123.456.789", nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | Y | +| 6 | Approves an NFT allowance to an empty spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId="", nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | Y | +| 7 | Approves an NFT allowance to a deleted spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_DELETED response code from the network. | Y | +| 8 | Approves an NFT allowance to a spender account from an owner account with a token that doesn't exist | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId="123.456.789", nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_TOKEN_ID response code from the network. | Y | +| 9 | Approves an NFT allowance to a spender account from an owner account with an empty token ID | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId="", nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | Y | +| 10 | Approves an NFT allowance to a spender account from an owner account with a deleted token | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an TOKEN_WAS_DELETED response code from the network. | Y | +| 11 | Approves an NFT allowance to a delegate spender account from a spender account with approved for all privileges from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId=}], commonTransactionParams.signers=[] | The allowance approval succeeds and the delegate spender account has the three NFT allowances. | Y | +| 12 | Approves an NFT allowance to a delegate spender account from a spender account that doesn't exist | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId="123.456.789"}] | The allowance approval fails with an INVALID_DELEGATING_SPENDER response code from the network. | Y | +| 13 | Approves an NFT allowance to a delegate spender account from an empty spender account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId=""}] | The allowance approval fails with an SDK internal error. | Y | +| 14 | Approves an NFT allowance to a delegate spender account from a deleted spender account with approved for all privileges from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId=}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_DELEGATING_SPENDER response code from the network. | Y | +| 15 | Approves an NFT allowance to a delegate spender account from a spender account without approved for all privileges from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId=}], commonTransactionParams.signers=[] | The allowance approval fails with an DELEGATING_SPENDER_DOES_NOT_HAVE_APPROVE_FOR_ALL response code from the network. | Y | +| 16 | Approves an NFT allowance to an account from the same account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an SPENDER_ACCOUNT_SAME_AS_OWNER response code from the network. | Y | +| 17 | Approves an NFT allowance of a fungible token to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES response code from the network. | Y | +| 18 | Approves an NFT allowance to a spender account from an owner account after already granting an NFT allowance to another account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval succeeds and the new spender account has the three NFT allowances and the old spender account has 0. | Y | +| 19 | Approves an NFT allowance to a spender account from an owner account with a token frozen on the owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | +| 20 | Approves an NFT allowance to a spender account from an owner account with a token frozen on the spender account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | +| 21 | Approves an NFT allowance to a spender account from an owner account with a paused token | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | + +#### JSON Request Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "method": "approveAllowance", + "params": { + "allowances": [ + { + "ownerAccountId": "0.0.53232", + "spenderAccountId": "0.0.8532", + "nft": { + "tokenId": "0.0.573298", + "serialNumbers": [ + "123", + "456", + "789" + ], + "delegatingSpenderAccountId": "0.0.483257" + } + } + ], + "commonTransactionParams": { + "signers": [ + "3030020100300706052b8104000a04220420e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" + ] + } + } +} +``` + +#### JSON Response Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "result": { + "status": "SUCCESS" + } +} +``` + +### **ApproveNftAllowanceAllSerials:** + +- Approves an allowance of all NFTs of a particular token class to an account. + +| Test no | Name | Input | Expected response | Implemented (Y/N) | +|---------|--------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|-------------------| +| 1 | Approves an NFT allowance with approved for all privileges to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | +| 2 | Approves an NFT allowance with approved for all privileges to a spender account from an owner account that doesn't exist | allowances=[{ownerAccountId="123.456.789", spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | Y | +| 3 | Approves an NFT allowance with approved for all privileges to a spender account from an empty owner account | allowances=[{ownerAccountId="", spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}] | The allowance approval fails with an SDK internal error. | Y | +| 4 | Approves an NFT allowance with approved for all privileges to a spender account from a deleted owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | Y | +| 5 | Approves an NFT allowance with approved for all privileges to a spender account that doesn't exist from an owner account | allowances=[{ownerAccountId=, spenderAccountId="123.456.789", nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | Y | +| 6 | Approves an NFT allowance with approved for all privileges to an empty spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId="", nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | Y | +| 7 | Approves an NFT allowance with approved for all privileges to a deleted spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | Y | +| 8 | Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a token that doesn't exist | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId="123.456.789", nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_TOKEN_ID response code from the network. | Y | +| 9 | Approves an NFT allowance with approved for all privileges to a spender account from an owner account with an empty token ID | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId="", nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | Y | +| 10 | Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a deleted token | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an TOKEN_WAS_DELETED response code from the network. | Y | +| 11 | Approves an NFT allowance with approved for all privileges to an account from the same account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an SPENDER_ACCOUNT_SAME_AS_OWNER response code from the network. | Y | +| 12 | Approves an NFT allowance with approved for all privileges of a fungible token to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval fails with an FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES response code from the network. | Y | +| 13 | Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a token frozen on the owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | +| 14 | Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a token frozen on the spender account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | +| 15 | Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a paused token | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | + +#### JSON Request Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "method": "approveAllowance", + "params": { + "allowances": [ + { + "ownerAccountId": "0.0.53232", + "spenderAccountId": "0.0.8532", + "nft": { + "tokenId": "0.0.573298", + "approvedForAll": true + } + } + ], + "commonTransactionParams": { + "signers": [ + "3030020100300706052b8104000a04220420e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" + ] + } + } +} +``` + +#### JSON Response Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "result": { + "status": "SUCCESS" + } +} +``` + +### **DeleteNftAllowanceAllSerials:** + +- Deletes an allowance of NFTs of a particular token class to an account. + +| Test no | Name | Input | Expected response | Implemented (Y/N) | +|---------|----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|-------------------| +| 1 | Deletes an NFT allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion succeeds and the spender account has the zero NFT allowances. | Y | +| 2 | Deletes an NFT allowance to a spender account from an owner account that doesn't exist | allowances=[{ownerAccountId="123.456.789", spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}] | The allowance deletion fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | Y | +| 3 | Deletes an NFT allowance to a spender account from an empty owner account | allowances=[{ownerAccountId="", spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}] | The allowance deletion fails with an SDK internal error. | Y | +| 4 | Deletes an NFT allowance to a spender account from a deleted owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an ACCOUNT_DELETED response code from the network. | Y | +| 5 | Deletes an NFT allowance to a spender account that doesn't exist from an owner account | allowances=[{ownerAccountId=, spenderAccountId="123.456.789", nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | Y | +| 6 | Deletes an NFT allowance to an empty spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId="", nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an SDK internal error. | Y | +| 7 | Deletes an NFT allowance to a deleted spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an ACCOUNT_DELETED response code from the network. | Y | +| 8 | Deletes an NFT allowance to a spender account from an owner account with a token that doesn't exist | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId="123.456.789", nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an INVALID_TOKEN_ID response code from the network. | Y | +| 9 | Deletes an NFT allowance to a spender account from an owner account with an empty token ID | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId="", nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an SDK internal error. | Y | +| 10 | Deletes an NFT allowance to a spender account from an owner account with a deleted token | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an TOKEN_WAS_DELETED response code from the network. | Y | +| 11 | Deletes an NFT allowance to an account from the same account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an SPENDER_ACCOUNT_SAME_AS_OWNER response code from the network. | Y | +| 12 | Deletes an NFT allowance of a fungible token to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion fails with an FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES response code from the network. | Y | +| 13 | Deletes an NFT allowance that doesn't exist to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance deletion succeeds and the spender account has the zero NFT allowances. | Y | +| 14 | Deletes an NFT allowance to a spender account from an owner account with a token frozen on the owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | +| 15 | Deletes an NFT allowance to a spender account from an owner account with a token frozen on the spender account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | +| 16 | Deletes an NFT allowance to a spender account from an owner account with a paused token | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.approvedForAll=false}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | Y | + +#### JSON Request Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "method": "approveAllowance", + "params": { + "allowances": [ + { + "ownerAccountId": "0.0.53232", + "spenderAccountId": "0.0.8532", + "nft": { + "tokenId": "0.0.573298" + } + } + ], + "commonTransactionParams": { + "signers": [ + "3030020100300706052b8104000a04220420e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" + ] + } + } +} +``` + +#### JSON Response Example + +```json +{ + "jsonrpc": "2.0", + "id": 99232, + "result": { + "status": "SUCCESS" + } +} +``` diff --git a/docs/test-specifications/crypto-service/AccountApproveAllowanceTransaction.md b/docs/test-specifications/crypto-service/AccountApproveAllowanceTransaction.md deleted file mode 100644 index 1ff3a53..0000000 --- a/docs/test-specifications/crypto-service/AccountApproveAllowanceTransaction.md +++ /dev/null @@ -1,245 +0,0 @@ -# AccountAllowanceApproveTransaction - Test specification - -## Description: -This test specification for AccountAllowanceApproveTransaction is to be one of many for testing the functionality of the Hedera SDKs. The SDK under test will use the language specific JSON-RPC server return responses back to the test driver. - -## Design: -Each test within the test specification is linked to one of the functions within AccountAllowanceApproveTransaction. Each function is tested with a mix of boundaries. The inputs for each test are a range of valid, minimum, maximum, negative and invalid values for the method. The expected response of a passed test can be a correct error response code or seen as the result of node queries. A successful transaction (the transaction reached consensus and was applied to state) can be determined by getting a `TransactionReceipt` or `TransactionRecord`, or can be determined by using queries such as `AccountInfoQuery` or `AccountBalanceQuery` and investigating for the required changes (creations, updates, etc.). The mirror node can also be used to determine if a transaction was successful via its rest API. Error codes are obtained from the response code proto files. - -**Transaction properties:** - -https://docs.hedera.com/hedera/sdks-and-apis/sdks/accounts-and-hbar/create-an-account - -**CryptoApproveAllowance protobufs:** - -https://github.com/hashgraph/hedera-protobufs/blob/main/services/crypto_approve_allowance.proto - -**Response codes:** - -https://github.com/hashgraph/hedera-protobufs/blob/main/services/response_code.proto - -**Mirror Node APIs:** - -https://docs.hedera.com/hedera/sdks-and-apis/rest-api - -## JSON-RPC API Endpoint Documentation - -### Method Name - -`approveAllowance` - -### Input Parameters - -| Parameter Name | Type | Required/Optional | Description/Notes | -|-------------------------|--------------------------------------------------|-------------------|----------------------------| -| allowances | list<[json object](allowances.md)> | optional | The allowance information. | -| commonTransactionParams | [json object](../commonTransactionParameters.md) | optional | | - -### Output Parameters - -| Parameter Name | Type | Description/Notes | -|----------------|--------|-------------------------------------------------------------------------------------------------| -| status | string | The status of the submitted `AccountAllowanceApproveTransaction` (from a `TransactionReceipt`). | - -### Additional Notes - -The tests contained in this specification will assume that valid owner and spender accounts were already successfully created. will denote the ID of the owner account and will denote the private key of the account as a DER-encoded hex string. will the denote the ID of the spender account, and will denote the private key of the account as a DER-encoded hex string. For tests that require tokens, they will assume a valid token has already been created. For simplicity, the treasury account of the token will be the owner account. If the token is fungible, the initial and max supply will be 1000. If the token is non-fungible, three NFTs should be minted. The token will also be associated with the spender account. will denote the ID of this token. , , and will denote the serial numbers of the minted NFTs. - -## Function Tests - -### **ApproveHbarAllowance:** - -- Approves an allowance of Hbar to an account. - -| Test no | Name | Input | Expected response | Implemented (Y/N) | -|---------|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|-------------------| -| 1 | Approves an hbar allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the allowance. | N | -| 2 | Approves an hbar allowance to a spender account from an owner account that doesn't exist | allowances=[{ownerAccountId="123.456.789", spenderAccountId=, hbar.amount="10"}] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | N | -| 3 | Approves an hbar allowance to a spender account from an empty owner account | allowances=[{ownerAccountId="", spenderAccountId=, hbar.amount="10"}] | The allowance approval fails with an SDK internal error. | N | -| 4 | Approves an hbar allowance to a spender account from a deleted owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_WAS_DELETED response code from the network. | N | -| 5 | Approves an hbar allowance to a spender account that doesn't exist from an owner account | allowances=[{ownerAccountId=, spenderAccountId="123.456.789", hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | N | -| 6 | Approves an hbar allowance to an empty spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId="", hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | N | -| 7 | Approves an hbar allowance to a deleted spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_WAS_DELETED response code from the network. | N | -| 8 | Approves a 0 hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="0"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has no allowance. | N | -| 9 | Approves a -1 hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="-1"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | N | -| 10 | Approves a 9,223,372,036,854,775,806 (int64 max - 1) hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="9223372036854775806"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has an allowance of 9,223,372,036,854,775,806 hbar. | N | -| 11 | Approves a 9,223,372,036,854,775,807 (int64 max) hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="9223372036854775807"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has an allowance of 9,223,372,036,854,775,807 hbar. | N | -| 12 | Approves a -9,223,372,036,854,775,808 (int64 min) hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="-9223372036854775808"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | N | -| 13 | Approves a -9,223,372,036,854,775,807 (int64 min + 1) hbar allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="-9223372036854775807"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | N | -| 14 | Approves an hbar allowance to an account from the same account | allowances=[{ownerAccountId=, spenderAccountId=, hbar.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SPENDER_ACCOUNT_SAME_AS_OWNER response code from the network. | N | - -#### JSON Request Example - -```json -{ - "jsonrpc": "2.0", - "id": 99232, - "method": "approveAllowance", - "params": { - "allowances": [ - { - "ownerAccountId": "0.0.53232", - "spenderAccountId": "0.0.8532", - "hbar": { - "amount": "100" - } - } - ], - "commonTransactionParams": { - "signers": [ - "3030020100300706052b8104000a04220420e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" - ] - } - } -} -``` - -#### JSON Response Example - -```json -{ - "jsonrpc": "2.0", - "id": 99232, - "result": { - "status": "SUCCESS" - } -} -``` - -### **ApproveTokenAllowance:** - -- Approves an allowance of a token to an account. - -| Test no | Name | Input | Expected response | Implemented (Y/N) | -|---------|-----------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|-------------------| -| 1 | Approves a token allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the allowance. | N | -| 2 | Approves a token allowance to a spender account from an owner account that doesn't exist | allowances=[{ownerAccountId="123.456.789", spenderAccountId=, token.tokenId=, token.amount="10"}] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | N | -| 3 | Approves a token allowance to a spender account from an empty owner account | allowances=[{ownerAccountId="", spenderAccountId=, token.tokenId=, token.amount="10"}] | The allowance approval fails with an SDK internal error. | N | -| 4 | Approves a token allowance to a spender account from a deleted owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_WAS_DELETED response code from the network. | N | -| 5 | Approves a token allowance to a spender account that doesn't exist from an owner account | allowances=[{ownerAccountId=, spenderAccountId="123.456.789", token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | N | -| 6 | Approves a token allowance to an empty spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId="", token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | N | -| 7 | Approves a token allowance to a deleted spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_WAS_DELETED response code from the network. | N | -| 8 | Approves a 0 token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="0"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has no allowance. | N | -| 9 | Approves a -1 token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="-1"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | N | -| 10 | Approves a 9,223,372,036,854,775,806 (int64 max - 1) token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="9223372036854775806"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has an allowance of 9,223,372,036,854,775,806 hbar. | N | -| 11 | Approves a 9,223,372,036,854,775,807 (int64 max) token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="9223372036854775807"}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has an allowance of 9,223,372,036,854,775,807 hbar. | N | -| 12 | Approves a -9,223,372,036,854,775,808 (int64 min) token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="-9223372036854775808"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | N | -| 13 | Approves a -9,223,372,036,854,775,807 (int64 min + 1) token allowance to a spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="-9223372036854775807"}], commonTransactionParams.signers=[] | The allowance approval fails with an NEGATIVE_ALLOWANCE_AMOUNT response code from the network. | N | -| 14 | Approves a token allowance to a spender account from an owner account with a token that doesn't exist | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId="123.456.789", token.amount="-10"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_TOKEN_ID response code from the network. | N | -| 15 | Approves a token allowance to a spender account from an owner account with an empty token ID | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId="", token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | N | -| 16 | Approves a token allowance to a spender account from an owner account with a deleted token | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an TOKEN_WAS_DELETED response code from the network. | N | -| 17 | Approves a token allowance to an account from the same account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an SPENDER_ACCOUNT_SAME_AS_OWNER response code from the network. | N | -| 18 | Approves a token allowance greater than the token's max supply to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10000"}], commonTransactionParams.signers=[] | The allowance approval fails with an AMOUNT_EXCEEDS_TOKEN_MAX_SUPPLY response code from the network. | N | -| 19 | Approves an NFT allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, token.amount="10"}], commonTransactionParams.signers=[] | The allowance approval fails with an NFT_IN_FUNGIBLE_TOKEN_ALLOWANCES response code from the network. | N | - -#### JSON Request Example - -```json -{ - "jsonrpc": "2.0", - "id": 99232, - "method": "approveAllowance", - "params": { - "allowances": [ - { - "ownerAccountId": "0.0.53232", - "spenderAccountId": "0.0.8532", - "token": { - "amount": "100", - "tokenId": "0.0.573298" - } - } - ], - "commonTransactionParams": { - "signers": [ - "3030020100300706052b8104000a04220420e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" - ] - } - } -} -``` - -#### JSON Response Example - -```json -{ - "jsonrpc": "2.0", - "id": 99232, - "result": { - "status": "SUCCESS" - } -} -``` - -### **ApproveTokenNftAllowance:** - -- Approves an allowance of an NFT to an account. - -| Test no | Name | Input | Expected response | Implemented (Y/N) | -|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|-------------------| -| 1 | Approves an NFT allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has the three NFT allowances. | N | -| 2 | Approves an NFT allowance to a spender account from an owner account that doesn't exist | allowances=[{ownerAccountId="123.456.789", spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}] | The allowance approval fails with an INVALID_ALLOWANCE_OWNER_ID response code from the network. | N | -| 3 | Approves an NFT allowance to a spender account from an empty owner account | allowances=[{ownerAccountId="", spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}] | The allowance approval fails with an SDK internal error. | N | -| 4 | Approves an NFT allowance to a spender account from a deleted owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_WAS_DELETED response code from the network. | N | -| 5 | Approves an NFT allowance to a spender account that doesn't exist from an owner account | allowances=[{ownerAccountId=, spenderAccountId="123.456.789", nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_ALLOWANCE_SPENDER_ID response code from the network. | N | -| 6 | Approves an NFT allowance to an empty spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId="", nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | N | -| 7 | Approves an NFT allowance to a deleted spender account from a owner account | allowances=[{ownerAccountId=, spenderAccountId=, nft.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an ACCOUNT_WAS_DELETED response code from the network. | N | -| 8 | Approves an NFT allowance to a spender account from an owner account with a token that doesn't exist | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId="123.456.789", nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_TOKEN_ID response code from the network. | N | -| 9 | Approves an NFT allowance to a spender account from an owner account with an empty token ID | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId="", nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | N | -| 10 | Approves an NFT allowance to a spender account from an owner account with a deleted token | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an TOKEN_WAS_DELETED response code from the network. | N | -| 11 | Approves an NFT allowance to a spender account from an owner account with approved for all privileges | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ], nft.approvedForAll=true}], commonTransactionParams.signers=[] | The allowance approval succeeds and the spender account has approved for all privileges. | N | -| 12 | Approves an NFT allowance to a spender account with approved for all privileges from an owner account with a delegate spender | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId=}], commonTransactionParams.signers=[] | The allowance approval succeeds and the delegate spender account has the three NFT allowances. | N | -| 13 | Approves an NFT allowance to a spender account with approved for all privileges from an owner account with a delegate spender that doesn't exist | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId="123.456.789"}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_DELEGATING_SPENDER response code from the network. | N | -| 14 | Approves an NFT allowance to a spender account with approved for all privileges from an owner account with an empty delegate spender | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId=""}], commonTransactionParams.signers=[] | The allowance approval fails with an SDK internal error. | N | -| 15 | Approves an NFT allowance to a spender account with approved for all privileges from an owner account with a deleted delegate spender | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId=}], commonTransactionParams.signers=[] | The allowance approval fails with an INVALID_DELEGATING_SPENDER response code from the network. | N | -| 16 | Approves an NFT allowance to a spender account with approved for all privileges from an owner account with a delegate spender and approved for all privileges | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ], nft.approvedForAll=true, nft.delegateSpenderAccountId=}], commonTransactionParams.signers=[] | The allowance approval fails with an DELEGATING_SPENDER_CANNOT_GRANT_APPROVE_FOR_ALL response code from the network. | N | -| 17 | Approves an NFT allowance to a spender account without approved for all privileges from an owner account with a delegate spender | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ], nft.delegateSpenderAccountId=}], commonTransactionParams.signers=[] | The allowance approval fails with an DELEGATING_SPENDER_DOES_NOT_HAVE_APPROVE_FOR_ALL response code from the network. | N | -| 18 | Approves an NFT allowance to an account from the same account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an SPENDER_ACCOUNT_SAME_AS_OWNER response code from the network. | N | -| 19 | Approves an NFT allowance greater than the token's max supply to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an AMOUNT_EXCEEDS_TOKEN_MAX_SUPPLY response code from the network. | N | -| 20 | Approves a fungible token allowance to a spender account from an owner account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval fails with an FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES response code from the network. | N | -| 21 | Approves an NFT allowance to a spender account from an owner account after already granting an NFT allowance to another account | allowances=[{ownerAccountId=, spenderAccountId=, token.tokenId=, nft.serialNumbers=[, , ]}], commonTransactionParams.signers=[] | The allowance approval succeeds and the new spender account has the three NFT allowances and the old spender account has 0. | N | - -#### JSON Request Example - -```json -{ - "jsonrpc": "2.0", - "id": 99232, - "method": "approveAllowance", - "params": { - "allowances": [ - { - "ownerAccountId": "0.0.53232", - "spenderAccountId": "0.0.8532", - "nft": { - "tokenId": "0.0.573298", - "serialNumbers": [ - "123", - "456", - "789" - ], - "approvedForAll": true, - "delegatingSpenderAccountId": "0.0.483257" - } - } - ], - "commonTransactionParams": { - "signers": [ - "3030020100300706052b8104000a04220420e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" - ] - } - } -} -``` - -#### JSON Response Example - -```json -{ - "jsonrpc": "2.0", - "id": 99232, - "result": { - "status": "SUCCESS" - } -} -``` diff --git a/docs/test-specifications/crypto-service/allowances.md b/docs/test-specifications/crypto-service/allowances.md index d07977b..4b7b503 100644 --- a/docs/test-specifications/crypto-service/allowances.md +++ b/docs/test-specifications/crypto-service/allowances.md @@ -6,8 +6,8 @@ Allowances can be granted to accounts to allow that account to spend on behalf o | Parameter Name | Type | Required/Optional | Description/Notes | |------------------|-------------|-------------------|--------------------------------------------------------------------------------------------------------------------------------------| -| ownerAccountId | string | optional | The ID of the account granting the allowance. | -| spenderAccountId | string | optional | The ID of the account being granted the allowance. | +| ownerAccountId | string | required | The ID of the account granting the allowance. | +| spenderAccountId | string | required | The ID of the account being granted the allowance. | | hbar | json object | optional | REQUIRED if `token` and `nft` are not provided. The parameters of the [HBAR Allowance](#hbar-allowance-object-definition) to grant. | | token | json object | optional | REQUIRED if `hbar` and `nft` are not provided. The parameters of the [Token Allowance](#token-allowance-object-definition) to grant. | | nft | json object | optional | REQUIRED if `hbar` and `token` are not provided. The parameters of the [NFT Allowance](#nft-allowance-object-definition) to grant. | @@ -16,23 +16,23 @@ Allowances can be granted to accounts to allow that account to spend on behalf o | Parameter Name | Type | Required/Optional | Description/Notes | |---------------------|--------|-------------------|--------------------------------------| -| amount | string | optional | The amount of HBAR to be allowanced. | +| amount | string | required | The amount of HBAR to be allowanced. | ### Token Allowance Object Definition | Parameter Name | Type | Required/Optional | Description/Notes | |----------------|--------|-------------------|-------------------------------------------| -| tokenId | string | optional | The ID of the token to be allowanced. | -| amount | string | optional | The amount of the token to be allowanced. | +| tokenId | string | required | The ID of the token to be allowanced. | +| amount | string | required | The amount of the token to be allowanced. | ### NFT Allowance Object Definition -| Parameter Name | Type | Required/Optional | Description/Notes | -|--------------------------|--------------|-------------------|------------------------------------------------------------------------------------------------------------------------| -| tokenId | string | optional | The ID of the token to be allowanced. | -| serialNumbers | list | optional | The serial numbers of the NFTs to be allowanced. | -| approvedForAll | bool | optional | Should the spender be granted access to all the owner's NFTs of the tokenId class (currently owned and in the future)? | -| delegateSpenderAccountId | string | optional | The ID of the account of a spender is granted approvedForAll access and can grant NFT allowances to another spender. | +| Parameter Name | Type | Required/Optional | Description/Notes | +|--------------------------|--------------|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| tokenId | string | required | The ID of the token to be allowanced. | +| serialNumbers | list | optional | REQUIRED if `approvedForAll` is not provided. The serial numbers of the NFTs to be allowanced. | +| approvedForAll | bool | optional | REQUIRED if `serialNumbers` is not provided. Should the spender be granted access to all the owner's NFTs of the tokenId class (currently owned and in the future)? | +| delegateSpenderAccountId | string | optional | The ID of the account of a spender who is already granted approvedForAll privileges and can grant NFT allowances to another spender. | ## Example Usage diff --git a/src/services/MirrorNodeClient.ts b/src/services/MirrorNodeClient.ts index 75e459e..5734d0b 100644 --- a/src/services/MirrorNodeClient.ts +++ b/src/services/MirrorNodeClient.ts @@ -3,9 +3,11 @@ import { retryOnError } from "../utils/helpers/retry-on-error"; class MirrorNodeClient { private mirrorNodeRestUrl: string | undefined; + private mirrorNodeRestJavaUrl: string | undefined; constructor() { this.mirrorNodeRestUrl = process.env.MIRROR_NODE_REST_URL; + this.mirrorNodeRestJavaUrl = process.env.MIRROR_NODE_REST_JAVA_URL; } // TODO: Get mirror node interface with OpenAPI @@ -25,6 +27,30 @@ class MirrorNodeClient { const url = `${this.mirrorNodeRestUrl}/api/v1/tokens/${tokenId}`; return retryOnError(async () => fetchData(url)); } + + // TODO: Get mirror node interface with OpenAPI + async getAccountNfts(accountId: string, tokenId: string) { + const url = `${this.mirrorNodeRestUrl}/api/v1/accounts/${accountId}/nfts?token.id=${tokenId}`; + return retryOnError(async () => fetchData(url)); + } + + // TODO: Get mirror node interface with OpenAPI + async getHbarAllowances(accountId: string): Promise { + const url = `${this.mirrorNodeRestUrl}/api/v1/accounts/${accountId}/allowances/crypto`; + return retryOnError(async () => fetchData(url)); + } + + // TODO: Get mirror node interface with OpenAPI + async getTokenAllowances(accountId: string): Promise { + const url = `${this.mirrorNodeRestUrl}/api/v1/accounts/${accountId}/allowances/tokens`; + return retryOnError(async () => fetchData(url)); + } + + // TODO: Get mirror node interface with OpenAPI + async getNftAllowances(accountId: string): Promise { + const url = `${this.mirrorNodeRestJavaUrl}/api/v1/accounts/${accountId}/allowances/nfts`; + return retryOnError(async () => fetchData(url)); + } } export default new MirrorNodeClient(); diff --git a/src/tests/crypto-service/test-account-allowance-approve-transaction.ts b/src/tests/crypto-service/test-account-allowance-approve-transaction.ts new file mode 100644 index 0000000..a2ab10f --- /dev/null +++ b/src/tests/crypto-service/test-account-allowance-approve-transaction.ts @@ -0,0 +1,3680 @@ +import { assert, expect } from "chai"; + +import { JSONRPCRequest } from "@services/Client"; +import mirrorNodeClient from "@services/MirrorNodeClient"; + +import { setOperator } from "@helpers/setup-tests"; +import { retryOnError } from "@helpers/retry-on-error"; + +import { ErrorStatusCodes } from "@enums/error-status-codes"; + +/** + * Tests for AccountAllowanceApproveTransaction + */ +describe("AccountAllowanceApproveTransaction", function () { + // Tests should not take longer than 30 seconds to fully execute. + this.timeout(30000); + + // Each test requires valid owner and spender accounts to be created. + let ownerAccountId: string, + ownerPrivateKey: string, + spenderAccountId: string, + spenderPrivateKey: string; + beforeEach(async function () { + await setOperator( + this, + process.env.OPERATOR_ACCOUNT_ID as string, + process.env.OPERATOR_ACCOUNT_PRIVATE_KEY as string, + ); + + ownerPrivateKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + spenderPrivateKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + ownerAccountId = ( + await JSONRPCRequest(this, "createAccount", { + key: ownerPrivateKey, + }) + ).accountId; + + spenderAccountId = ( + await JSONRPCRequest(this, "createAccount", { + key: spenderPrivateKey, + }) + ).accountId; + }); + afterEach(async function () { + await JSONRPCRequest(this, "reset"); + }); + + async function verifyHbarAllowance( + ownerAccountId: string, + spenderAccountId: string, + amount: string, + ) { + const mirrorNodeInfo = + await mirrorNodeClient.getHbarAllowances(ownerAccountId); + + let foundAllowance = false; + for (let i = 0; i < mirrorNodeInfo.allowances.length; i++) { + if ( + mirrorNodeInfo.allowances[i].owner === ownerAccountId && + mirrorNodeInfo.allowances[i].spender === spenderAccountId && + mirrorNodeInfo.allowances[i].amount.toString() === amount + ) { + foundAllowance = true; + break; + } + } + + expect(foundAllowance).to.be.true; + } + + async function verifyTokenAllowance( + ownerAccountId: string, + spenderAccountId: string, + tokenId: string, + amount: string, + ) { + const mirrorNodeInfo = + await mirrorNodeClient.getTokenAllowances(ownerAccountId); + + let foundAllowance = false; + for (let i = 0; i < mirrorNodeInfo.allowances.length; i++) { + if ( + mirrorNodeInfo.allowances[i].owner === ownerAccountId && + mirrorNodeInfo.allowances[i].spender === spenderAccountId && + mirrorNodeInfo.allowances[i].token_id === tokenId && + mirrorNodeInfo.allowances[i].amount.toString() === amount + ) { + foundAllowance = true; + break; + } + } + + expect(foundAllowance).to.be.true; + } + + async function verifyNftAllowance( + allowanceExists: boolean, + ownerAccountId: string, + spenderAccountId: string, + tokenId: string, + serialNumber: string, + delegatingSpenderAccountId: string | null = null, + ) { + const mirrorNodeInfo = await mirrorNodeClient.getAccountNfts( + ownerAccountId, + tokenId, + ); + + let foundAllowance = false; + for (let i = 0; i < mirrorNodeInfo.nfts.length; i++) { + if ( + mirrorNodeInfo.nfts[i].account_id === ownerAccountId && + mirrorNodeInfo.nfts[i].spender === spenderAccountId && + mirrorNodeInfo.nfts[i].token_id === tokenId && + mirrorNodeInfo.nfts[i].serial_number.toString() === serialNumber && + (!delegatingSpenderAccountId || + mirrorNodeInfo.nfts[i].delegating_spender === + delegatingSpenderAccountId) + ) { + foundAllowance = true; + break; + } + } + + expect(foundAllowance).to.equal(allowanceExists); + } + + async function verifyApprovedForAllAllowance( + approvedForAll: boolean, + ownerAccountId: string, + spenderAccountId: string, + tokenId: string, + ) { + const mirrorNodeInfo = + await mirrorNodeClient.getNftAllowances(ownerAccountId); + + let foundAllowance = false; + for (let i = 0; i < mirrorNodeInfo.allowances.length; i++) { + if ( + mirrorNodeInfo.allowances[i].token_id === tokenId && + mirrorNodeInfo.allowances[i].owner === ownerAccountId && + mirrorNodeInfo.allowances[i].spender === spenderAccountId + ) { + foundAllowance = true; + break; + } + } + + expect(foundAllowance).to.equal(approvedForAll); + } + + describe("ApproveHbarAllowance", function () { + it("(#1) Approves an hbar allowance to a spender account from an owner account", async function () { + const amount = "10"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyHbarAllowance(ownerAccountId, spenderAccountId, amount), + ); + }); + + it("(#2) Approves an hbar allowance to a spender account from an owner account that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "123.456.789", + spenderAccountId, + hbar: { + amount: "10", + }, + }, + ], + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_OWNER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Approves an hbar allowance to a spender account from an empty owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "", + spenderAccountId, + hbar: { + amount: "10", + }, + }, + ], + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#4) Approves an hbar allowance to a spender account from a deleted owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: ownerAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_OWNER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#5) Approves an hbar allowance to a spender account that doesn't exist from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "123.456.789", + hbar: { + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#6) Approves an hbar allowance to an empty spender account from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "", + hbar: { + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#7) Approves an hbar allowance to a deleted spender account from a owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: spenderAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#8) Approves a 0 hbar allowance to a spender account from a owner account", async function () { + const amount = "0"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + // No real good way to confirm this, since an allowance of zero doesn't show up in the allowance information from mirror node, but also unsure about how long it would take to go through consensus and be confirmed. + await retryOnError(async () => { + const mirrorNodeInfo = + await mirrorNodeClient.getHbarAllowances(spenderAccountId); + expect(mirrorNodeInfo.allowances.length).to.equal(0); + }); + }); + + it("(#9) Approves a -1 hbar allowance to a spender account from a owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount: "-1", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "NEGATIVE_ALLOWANCE_AMOUNT"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#10) Approves a 9,223,372,036,854,775,806 (int64 max - 1) hbar allowance to a spender account from a owner account", async function () { + const amount = "9223372036854775806"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyHbarAllowance(ownerAccountId, spenderAccountId, amount), + ); + }); + + it("(#11) Approves a 9,223,372,036,854,775,807 (int64 max) hbar allowance to a spender account from a owner account", async function () { + const amount = "9223372036854775807"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyHbarAllowance(ownerAccountId, spenderAccountId, amount), + ); + }); + + it("(#12) Approves a -9,223,372,036,854,775,808 (int64 min) hbar allowance to a spender account from a owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount: "-9223372036854775808", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "NEGATIVE_ALLOWANCE_AMOUNT"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#13) Approves a -9,223,372,036,854,775,807 (int64 min + 1) hbar allowance to a spender account from a owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + hbar: { + amount: "-9223372036854775807", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "NEGATIVE_ALLOWANCE_AMOUNT"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#14) Approves an hbar allowance to an account from the same account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: ownerAccountId, + hbar: { + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "SPENDER_ACCOUNT_SAME_AS_OWNER"); + return; + } + + assert.fail("Should throw an error"); + }); + }); + + describe("ApproveTokenAllowance", function () { + // Each test here requires a token to be created. + let tokenId: string; + this.beforeEach(async function () { + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + }) + ).tokenId; + + await JSONRPCRequest(this, "associateToken", { + accountId: ownerAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + }); + + it("(#1) Approves a token allowance to a spender account from an owner account", async function () { + const amount = "10"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyTokenAllowance(ownerAccountId, spenderAccountId, tokenId, amount), + ); + }); + + it("(#2) Approves a token allowance to a spender account from an owner account that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "123.456.789", + spenderAccountId, + token: { + tokenId, + amount: "10", + }, + }, + ], + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_OWNER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Approves a token allowance to a spender account from an empty owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "", + spenderAccountId, + token: { + tokenId, + amount: "10", + }, + }, + ], + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#4) Approves a token allowance to a spender account from a deleted owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: ownerAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_OWNER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#5) Approves a token allowance to a spender account that doesn't exist from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "123.456.789", + token: { + tokenId, + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#6) Approves a token allowance to an empty spender account from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "", + token: { + tokenId, + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#7) Approves a token allowance to a deleted spender account from an owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: spenderAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#8) Approves a 0 token allowance to a spender account from a owner account", async function () { + const amount = "0"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + // No real good way to confirm this, since an allowance of zero doesn't show up in the allowance information from mirror node, but also unsure about how long it would take to go through consensus and be confirmed. + await retryOnError(async () => { + const mirrorNodeInfo = + await mirrorNodeClient.getTokenAllowances(spenderAccountId); + expect(mirrorNodeInfo.allowances.length).to.equal(0); + }); + }); + + it("(#9) Approves a -1 token allowance to a spender account from a owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount: "-1", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "NEGATIVE_ALLOWANCE_AMOUNT"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#10) Approves a 9,223,372,036,854,775,806 (int64 max - 1) token allowance to a spender account from a owner account", async function () { + const amount = "9223372036854775806"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyTokenAllowance(ownerAccountId, spenderAccountId, tokenId, amount), + ); + }); + + it("(#11) Approves a 9,223,372,036,854,775,807 (int64 max) token allowance to a spender account from a owner account", async function () { + const amount = "9223372036854775807"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyTokenAllowance(ownerAccountId, spenderAccountId, tokenId, amount), + ); + }); + + it("(#12) Approves a -9,223,372,036,854,775,808 (int64 min) token allowance to a spender account from a owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount: "-9223372036854775808", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "NEGATIVE_ALLOWANCE_AMOUNT"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#13) Approves a -9,223,372,036,854,775,807 (int64 min + 1) token allowance to a spender account from a owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount: "-9223372036854775807", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "NEGATIVE_ALLOWANCE_AMOUNT"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#14) Approves a token allowance to a spender account from an owner account with a token that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId: "123.456.789", + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_TOKEN_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#15) Approves a token allowance to a spender account from an owner account with an empty token ID", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId: "", + amount: "10", + }, + }, + ], + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#16) Approves a token allowance to a spender account from an owner account with a deleted token", async function () { + const adminKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + adminKey, + commonTransactionParams: { + signers: [adminKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "associateToken", { + accountId: ownerAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "deleteToken", { + tokenId, + commonTransactionParams: { + signers: [adminKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "TOKEN_WAS_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#17) Approves a token allowance to an account from the same account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: ownerAccountId, + token: { + tokenId, + amount: "10", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "SPENDER_ACCOUNT_SAME_AS_OWNER"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#18) Approves a token allowance greater than the token's max supply to a spender account from an owner account", async function () { + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + supplyType: "finite", + maxSupply: "1000", + }) + ).tokenId; + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount: "10000", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "AMOUNT_EXCEEDS_TOKEN_MAX_SUPPLY"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#19) Approves a token allowance of an NFT to a spender account from an owner account", async function () { + const supplyKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + supplyKey, + tokenType: "nft", + }) + ).tokenId; + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount: "10000", + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "NFT_IN_FUNGIBLE_TOKEN_ALLOWANCES"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#20) Approves a token allowance to a spender account from an owner account with a token frozen on the owner account", async function () { + const freezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + freezeKey, + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId: ownerAccountId, + commonTransactionParams: { + signers: [freezeKey], + }, + }); + + const amount = "10"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyTokenAllowance(ownerAccountId, spenderAccountId, tokenId, amount), + ); + }); + + it("(#21) Approves a token allowance to a spender account from an owner account with a token frozen on the spender account", async function () { + const freezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + freezeKey, + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId: spenderAccountId, + commonTransactionParams: { + signers: [freezeKey], + }, + }); + + const amount = "10"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyTokenAllowance(ownerAccountId, spenderAccountId, tokenId, amount), + ); + }); + + it("(#22) Approves a token allowance to a spender account from an owner account with a paused token", async function () { + const pauseKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + pauseKey, + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "pauseToken", { + tokenId, + commonTransactionParams: { + signers: [pauseKey], + }, + }); + + const amount = "10"; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + token: { + tokenId, + amount, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyTokenAllowance(ownerAccountId, spenderAccountId, tokenId, amount), + ); + }); + }); + + describe("ApproveNftTokenAllowance", function () { + // Each test here requires a token to be created. + let tokenId: string, supplyKey: string; + let metadata = ["1234", "5678", "90ab"]; + this.beforeEach(async function () { + supplyKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + }); + + it("(#1) Approves an NFT allowance to a spender account from an owner account", async function () { + const serialNumbers = ["1", "2", "3"]; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async function () { + await verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + serialNumbers[0], + ); + }); + + await retryOnError(async function () { + await verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + serialNumbers[1], + ); + }); + + await retryOnError(async function () { + await verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + serialNumbers[2], + ); + }); + }); + + it("(#2) Approves an NFT allowance to a spender account from an owner account that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "123.456.789", + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_OWNER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Approves an NFT allowance to a spender account from an empty owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "", + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal Error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#4) Approves an NFT allowance to a spender account from a deleted owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: ownerAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_OWNER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#5) Approves an NFT allowance to a spender account that doesn't exist from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "123.456.789", + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#6) Approves an NFT allowance to an empty spender account from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "", + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal Error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#7) Approves an NFT allowance to a deleted spender account from an owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: spenderAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#8) Approves an NFT allowance to a spender account from an owner account with a token that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId: "123.456.789", + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_TOKEN_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#9) Approves an NFT allowance to a spender account from an owner account with an empty token ID", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId: "", + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal Error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#10) Approves an NFT allowance to a spender account from an owner account with a deleted token", async function () { + const adminKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + const supplyKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + adminKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [adminKey, ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata: ["1234", "5678", "90ab"], + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "deleteToken", { + tokenId, + commonTransactionParams: { + signers: [adminKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "TOKEN_WAS_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#11) Approves an NFT allowance to a delegate spender account from a spender account with approved for all privileges from an owner account", async function () { + const key = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + const accountId = ( + await JSONRPCRequest(this, "createAccount", { + key, + }) + ).accountId; + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + const serialNumbers = ["1", "2", "3"]; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: accountId, + nft: { + tokenId, + serialNumbers, + delegateSpenderAccountId: spenderAccountId, + }, + }, + ], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await retryOnError(async () => { + await verifyNftAllowance( + true, + ownerAccountId, + accountId, + tokenId, + serialNumbers[0], + spenderAccountId, + ); + }); + + await retryOnError(async () => { + await verifyNftAllowance( + true, + ownerAccountId, + accountId, + tokenId, + serialNumbers[1], + spenderAccountId, + ); + }); + + await retryOnError(async () => { + await verifyNftAllowance( + true, + ownerAccountId, + accountId, + tokenId, + serialNumbers[2], + spenderAccountId, + ); + }); + }); + + it("(#12) Approves an NFT allowance to a delegate spender account from a spender account that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + delegateSpenderAccountId: "123.456.789", + }, + }, + ], + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_DELEGATING_SPENDER"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#13) Approves an NFT allowance to a delegate spender account from an empty spender account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + delegateSpenderAccountId: "", + }, + }, + ], + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Invalid error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#14) Approves an NFT allowance to a delegate spender account from a deleted spender account with approved for all privileges from an owner account", async function () { + const key = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + const accountId = ( + await JSONRPCRequest(this, "createAccount", { + key, + }) + ).accountId; + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: spenderAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: accountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + delegateSpenderAccountId: spenderAccountId, + }, + }, + ], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_DELEGATING_SPENDER"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#15) Approves an NFT allowance to a delegate spender account from a spender account without approved for all privileges from an owner account", async function () { + const key = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + const accountId = ( + await JSONRPCRequest(this, "createAccount", { + key, + }) + ).accountId; + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: accountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + delegateSpenderAccountId: spenderAccountId, + }, + }, + ], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.data.status, + "DELEGATING_SPENDER_DOES_NOT_HAVE_APPROVE_FOR_ALL", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#16) Approves an NFT allowance to an account from the same account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: ownerAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "SPENDER_ACCOUNT_SAME_AS_OWNER"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#17) Approves an NFT allowance of a fungible token to a spender account from an owner account", async function () { + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + tokenType: "ft", + }) + ).tokenId; + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: ownerAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#18) Approves an NFT allowance to a spender account from an owner account after already granting an NFT allowance to another account", async function () { + const key = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + const accountId = ( + await JSONRPCRequest(this, "createAccount", { + key, + }) + ).accountId; + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + const serialNumbers = ["1", "2", "3"]; + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: accountId, + nft: { + tokenId, + serialNumbers, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => { + await verifyNftAllowance( + true, + ownerAccountId, + accountId, + tokenId, + serialNumbers[0], + ); + }); + + await retryOnError(async () => { + await verifyNftAllowance( + true, + ownerAccountId, + accountId, + tokenId, + serialNumbers[1], + ); + }); + + await retryOnError(async () => { + await verifyNftAllowance( + true, + ownerAccountId, + accountId, + tokenId, + serialNumbers[2], + ); + }); + + await retryOnError(async () => { + const mirrorNodeInfo = + await mirrorNodeClient.getNftAllowances(spenderAccountId); + expect(mirrorNodeInfo.allowances.length).to.equal(0); + }); + }); + + it("(#19) Approves an NFT allowance to a spender account from an owner account with a token frozen on the owner account", async function () { + const freezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + freezeKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId: ownerAccountId, + commonTransactionParams: { + signers: [freezeKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "1", + ), + ); + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "2", + ), + ); + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "3", + ), + ); + }); + + it("(#20) Approves an NFT allowance to a spender account from an owner account with a token frozen on the spender account", async function () { + const freezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + freezeKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId: spenderAccountId, + commonTransactionParams: { + signers: [freezeKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "1", + ), + ); + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "2", + ), + ); + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "3", + ), + ); + }); + + it("(#21) Approves an NFT allowance to a spender account from an owner account with a paused token", async function () { + const pauseKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + pauseKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "pauseToken", { + tokenId, + commonTransactionParams: { + signers: [pauseKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + serialNumbers: ["1", "2", "3"], + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "1", + ), + ); + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "2", + ), + ); + await retryOnError(async () => + verifyNftAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + "3", + ), + ); + }); + }); + + describe("ApproveNftAllowanceAllSerials", function () { + // Each test here requires a token to be created. + let tokenId: string, supplyKey: string; + let metadata = ["1234", "5678", "90ab"]; + this.beforeEach(async function () { + supplyKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + }); + + it("(#1) Approves an NFT allowance with approved for all privileges to a spender account from an owner account", async function () { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + + it("(#2) Approves an NFT allowance with approved for all privileges to a spender account from an owner account that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "123.456.789", + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_OWNER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Approves an NFT allowance with approved for all privileges to a spender account from an empty owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "", + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#4) Approves an NFT allowance with approved for all privileges to a spender account from a deleted owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: ownerAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "ACCOUNT_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#5) Approves an NFT allowance with approved for all privileges to a spender account that doesn't exist from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "123.456.789", + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#6) Approves an NFT allowance with approved for all privileges to an empty spender account from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "", + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#7) Approves an NFT allowance with approved for all privileges to a deleted spender account from a owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: spenderAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#8) Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a token that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId: "123.456.789", + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_TOKEN_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#9) Approves an NFT allowance with approved for all privileges to a spender account from an owner account with an empty token ID", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId: "", + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#10) Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a deleted token", async function () { + const adminKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + const supplyKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + adminKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [adminKey, ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata: ["1234", "5678", "90ab"], + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "deleteToken", { + tokenId, + commonTransactionParams: { + signers: [adminKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "TOKEN_WAS_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#11) Approves an NFT allowance with approved for all privileges to an account from the same account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: ownerAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "SPENDER_ACCOUNT_SAME_AS_OWNER"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#12) Approves an NFT allowance with approved for all privileges of a fungible token to a spender account from an owner account", async function () { + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + tokenType: "ft", + }) + ).tokenId; + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#13) Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a token frozen on the owner account", async function () { + const freezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + freezeKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId: ownerAccountId, + commonTransactionParams: { + signers: [freezeKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + + it("(#14) Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a token frozen on the spender account", async function () { + const freezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + freezeKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId: spenderAccountId, + commonTransactionParams: { + signers: [freezeKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + + it("(#15) Approves an NFT allowance with approved for all privileges to a spender account from an owner account with a paused token", async function () { + const pauseKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + pauseKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "pauseToken", { + tokenId, + commonTransactionParams: { + signers: [pauseKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + true, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + }); + + describe("DeleteNftAllowanceAllSerials", function () { + // Each test here requires a token to be created. + let tokenId: string, supplyKey: string; + let metadata = ["1234", "5678", "90ab"]; + this.beforeEach(async function () { + supplyKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + }); + + it("(#1) Deletes an NFT allowance to a spender account from an owner account", async function () { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + false, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + + it("(#2) Deletes an NFT allowance to a spender account from an owner account that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "123.456.789", + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_OWNER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Deletes an NFT allowance to a spender account from an empty owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId: "", + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#4) Deletes an NFT allowance to a spender account from a deleted owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: ownerAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "ACCOUNT_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#5) Deletes an NFT allowance to a spender account that doesn't exist from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "123.456.789", + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_ALLOWANCE_SPENDER_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#6) Deletes an NFT allowance to an empty spender account from an owner account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: "", + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#7) Deletes an NFT allowance to a deleted spender account from a owner account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: spenderAccountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "ACCOUNT_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#8) Deletes an NFT allowance to a spender account from an owner account with a token that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId: "123.456.789", + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "INVALID_TOKEN_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#9) Deletes an NFT allowance to a spender account from an owner account with an empty token ID", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId: "", + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); + return; + } + + assert.fail("Should throw an error"); + }); + + it.skip("(#10) Deletes an NFT allowance to a spender account from an owner account with a deleted token", async function () { + const adminKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + const supplyKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + adminKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [adminKey, ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata: ["1234", "5678", "90ab"], + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await JSONRPCRequest(this, "deleteToken", { + tokenId, + commonTransactionParams: { + signers: [adminKey], + }, + }); + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "TOKEN_WAS_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#11) Deletes an NFT allowance to an account from the same account", async function () { + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId: ownerAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "SPENDER_ACCOUNT_SAME_AS_OWNER"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#12) Deletes an NFT allowance of a fungible token to a spender account from an owner account", async function () { + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID as string, + tokenType: "ft", + }) + ).tokenId; + + try { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + } catch (err: any) { + assert.equal(err.data.status, "FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#13) Deletes an NFT allowance that doesn't exist to a spender account from an owner account", async function () { + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + false, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + + it("(#14) Deletes an NFT allowance to a spender account from an owner account with a token frozen on the owner account", async function () { + const freezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + freezeKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId: ownerAccountId, + commonTransactionParams: { + signers: [freezeKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + false, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + + it("(#15) Deletes an NFT allowance to a spender account from an owner account with a token frozen on the spender account", async function () { + const freezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + freezeKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId: spenderAccountId, + commonTransactionParams: { + signers: [freezeKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + false, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + + it("(#16) Deletes an NFT allowance to a spender account from an owner account with a paused token", async function () { + const pauseKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: ownerAccountId, + pauseKey, + supplyKey, + tokenType: "nft", + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }) + ).tokenId; + + await JSONRPCRequest(this, "mintToken", { + tokenId, + metadata, + commonTransactionParams: { + signers: [supplyKey], + }, + }); + + await JSONRPCRequest(this, "associateToken", { + accountId: spenderAccountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [spenderPrivateKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: true, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await JSONRPCRequest(this, "pauseToken", { + tokenId, + commonTransactionParams: { + signers: [pauseKey], + }, + }); + + await JSONRPCRequest(this, "approveAllowance", { + allowances: [ + { + ownerAccountId, + spenderAccountId, + nft: { + tokenId, + approvedForAll: false, + }, + }, + ], + commonTransactionParams: { + signers: [ownerPrivateKey], + }, + }); + + await retryOnError(async () => + verifyApprovedForAllAllowance( + false, + ownerAccountId, + spenderAccountId, + tokenId, + ), + ); + }); + }); +});