Skip to content

Commit

Permalink
feat: added a new flow to let users manually configure transactions' …
Browse files Browse the repository at this point in the history
…gas limit on the System Contract DApp (#678)

* fix(docs): fixed typo in README DApp Playground

Signed-off-by: Logan Nguyen <[email protected]>

* update: updated gasLimit explanation

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new POST request to estimateGas() API on mirror-node

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to IHRC

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to TokenCreateCustom contract

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to TokenManagementContract

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to TokenQueryContract

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to TokenTransferContract

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to ExchangeRate

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to PRNG

Signed-off-by: Logan Nguyen <[email protected]>

* update: updated Service Fee explanation

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to ERC20

Signed-off-by: Logan Nguyen <[email protected]>

* feat: added new estimateGas flow to ERC721

Signed-off-by: Logan Nguyen <[email protected]>

* fix(test): fixed unit tests

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed typo MOCK_SINGER_ADDRESS to MOCK_SIGNER_ADDRESS

Signed-off-by: Logan Nguyen <[email protected]>

---------

Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node authored Feb 20, 2024
1 parent 939cd3f commit 1d07283
Show file tree
Hide file tree
Showing 55 changed files with 1,958 additions and 407 deletions.
2 changes: 1 addition & 1 deletion system-contract-dapp-playground/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Please follow this [instruction here](https://support.metamask.io/hc/en-us/artic
1. From the root directory (`hedera-smart-contract`), run the below commands to compile the smart contracts

```
npx install && npx hardhat compile
npm install && npx hardhat compile
```

2. Now, navigate back to the `system-contract-dapp-playground` directory and execute the `prerequisite-check` command using npm:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import {
handleErc20TokenPermissions,
} from '@/api/hedera/erc20-interactions';
import { Contract } from 'ethers';
import { MOCK_TX_HASH } from '../../utils/common/constants';
import {
MOCK_TX_HASH,
MOCK_GAS_LIMIT,
MOCK_HEDERA_NETWORK,
MOCK_SIGNER_ADDRESS,
} from '../../utils/common/constants';

describe('getERC20TokenInformation', () => {
const expectedSymbol = 'TKN';
Expand Down Expand Up @@ -90,8 +95,11 @@ describe('erc20Mint', () => {
it('should execute erc20Mint', async () => {
const res = await erc20Mint(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'0x7a575266b2020e262e9b1ad4eba3014d63630095',
120
120,
MOCK_GAS_LIMIT
);

// assertion
Expand All @@ -102,7 +110,14 @@ describe('erc20Mint', () => {
});

it('should failed with invalid recipient address', async () => {
const res = await erc20Mint(baseContract as unknown as Contract, '0xabc', 120);
const res = await erc20Mint(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'0xabc',
120,
MOCK_GAS_LIMIT
);
// assertion
expect(res.err).toBe('Invalid recipient address');
expect(erc20Mint).toBeCalled;
Expand All @@ -112,8 +127,11 @@ describe('erc20Mint', () => {
it('should failed with invalid token amount', async () => {
const res = await erc20Mint(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'0x7a575266b2020e262e9b1ad4eba3014d63630095',
-120
-120,
MOCK_GAS_LIMIT
);
// assertion
expect(res.err).toBe('Invalid token amount');
Expand Down Expand Up @@ -166,8 +184,11 @@ describe('Token Permissions', () => {
it('should execute erc20Approve', async () => {
const approveRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'approve',
'0x7a575266b2020e262e9b1ad4eba3014d63630095',
MOCK_GAS_LIMIT,
'',
120
);
Expand All @@ -182,8 +203,11 @@ describe('Token Permissions', () => {
it('should fail erc20Approve with Invalid spender address', async () => {
const approveRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'approve',
'0x3619',
MOCK_GAS_LIMIT,
'',
120
);
Expand All @@ -197,8 +221,11 @@ describe('Token Permissions', () => {
it('should execute erc20IncreaseAllowance', async () => {
const increaseAllowanceRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'increaseAllowance',
'0x7a575266b2020e262e9b1ad4eba3014d63630095',
MOCK_GAS_LIMIT,
'',
120
);
Expand All @@ -213,8 +240,11 @@ describe('Token Permissions', () => {
it('should fail erc20IncreaseAllowance with Invalid spender address', async () => {
const increaseAllowanceRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'increaseAllowance',
'0x3619',
MOCK_GAS_LIMIT,
'',
120
);
Expand All @@ -228,8 +258,11 @@ describe('Token Permissions', () => {
it('should execute erc20DecreaseAllowance', async () => {
const decreaseAllowanceRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'decreaseAllowance',
'0x7a575266b2020e262e9b1ad4eba3014d63630095',
MOCK_GAS_LIMIT,
'',
120
);
Expand All @@ -244,8 +277,11 @@ describe('Token Permissions', () => {
it('should fail erc20DecreaseAllowance with Invalid spender address', async () => {
const decreaseAllowanceRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'decreaseAllowance',
'0x3619',
MOCK_GAS_LIMIT,
'',
120
);
Expand All @@ -259,8 +295,11 @@ describe('Token Permissions', () => {
it('should execute erc20Allowance', async () => {
const allowanceRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'allowance',
'0x7a575266b2020e262e9b1ad4eba3014d63630095',
MOCK_GAS_LIMIT,
'0x7a575266b2020e262e9b1ad4eba3014d63630012'
);

Expand All @@ -273,8 +312,11 @@ describe('Token Permissions', () => {
it('should fail erc20Allowance with Invalid owner address', async () => {
const allowanceRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'allowance',
'0x7a575266b2020e262e9b1ad4eba3014d63630012',
MOCK_GAS_LIMIT,
'0x3619'
);

Expand All @@ -287,8 +329,11 @@ describe('Token Permissions', () => {
it('should fail erc20Allowance with Invalid spender address', async () => {
const allowanceRes = await handleErc20TokenPermissions(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'allowance',
'0x3619',
MOCK_GAS_LIMIT,
'0x7a575266b2020e262e9b1ad4eba3014d63630012'
);

Expand All @@ -314,9 +359,12 @@ describe('Transfer', () => {
it('should execute erc20Transfer', async () => {
const transferRes = await erc20Transfers(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'transfer',
'0x7a575266b2020e262e9b1ad4eba3014d63630012',
120
120,
MOCK_GAS_LIMIT
);

// assertion
Expand All @@ -327,7 +375,15 @@ describe('Transfer', () => {
});

it('should fail erc20Transfer with Invalid recipient address', async () => {
const transferRes = await erc20Transfers(baseContract as unknown as Contract, 'transfer', '0x112c', 120);
const transferRes = await erc20Transfers(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'transfer',
'0x112c',
120,
MOCK_GAS_LIMIT
);

// assertion
expect(transferRes.err).toBe('Invalid recipient address');
Expand All @@ -338,9 +394,12 @@ describe('Transfer', () => {
it('should execute erc20TransferFrom', async () => {
const transferFromRes = await erc20Transfers(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'transferFrom',
'0x7a575266b2020e262e9b1ad4eba3014d63630022',
120,
MOCK_GAS_LIMIT,
'0x7a575266b2020e262e9b1ad4eba3014d63630012'
);

Expand All @@ -354,8 +413,11 @@ describe('Transfer', () => {
it('should fail erc20TransferFrom with Invalid token owner address', async () => {
const transferFromRes = await erc20Transfers(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'transferFrom',
'0x7a575266b2020e262e9b1ad4eba3014d63630012',
MOCK_GAS_LIMIT,
120,
'0x112c'
);
Expand All @@ -369,9 +431,12 @@ describe('Transfer', () => {
it('should fail erc20TransferFrom with Invalid recipient address', async () => {
const transferFromRes = await erc20Transfers(
baseContract as unknown as Contract,
MOCK_SIGNER_ADDRESS,
MOCK_HEDERA_NETWORK,
'transferFrom',
'0x112c',
120,
MOCK_GAS_LIMIT,
'0x7a575266b2020e262e9b1ad4eba3014d63630012'
);

Expand Down
Loading

0 comments on commit 1d07283

Please sign in to comment.