diff --git a/contracts/test/burnable.ts b/contracts/test/burnable.ts index b8488e678..2bd6d9713 100644 --- a/contracts/test/burnable.ts +++ b/contracts/test/burnable.ts @@ -34,190 +34,194 @@ const expect = chai.expect let proxyAddress: ContractId -describe('Burn Tests', function () { - before(async function () { - // Deploy Token using Client - const result = await deployContractsWithSDK({ - name: TOKEN_NAME, - symbol: TOKEN_SYMBOL, - decimals: TOKEN_DECIMALS, - initialSupply: INIT_SUPPLY.toString(), - maxSupply: MAX_SUPPLY.toString(), - memo: TOKEN_MEMO, - account: operatorAccount, - privateKey: operatorPriKey, - publicKey: operatorPubKey, - isED25519Type: operatorIsE25519, - initialAmountDataFeed: INIT_SUPPLY.add( - BigNumber.from('100000') - ).toString(), +export const burnable = (deployedContracts: ContractId[]) => { + describe('Burn Tests', function () { + before(async function () { + // Deploy Token using Client + const [result] = await Promise.all([ + deployContractsWithSDK({ + name: TOKEN_NAME, + symbol: TOKEN_SYMBOL, + decimals: TOKEN_DECIMALS, + initialSupply: INIT_SUPPLY.toString(), + maxSupply: MAX_SUPPLY.toString(), + memo: TOKEN_MEMO, + account: operatorAccount, + privateKey: operatorPriKey, + publicKey: operatorPubKey, + isED25519Type: operatorIsE25519, + initialAmountDataFeed: INIT_SUPPLY.add( + BigNumber.from('100000') + ).toString(), + }), + ]) + deployedContracts.push(result[0]) + proxyAddress = deployedContracts[0] }) - proxyAddress = result[0] - }) + it('Admin account can grant and revoke burnable role to an account', async function () { + // Admin grants burn role : success + let result = await hasRole( + BURN_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + expect(result).to.equals(false) - it('Admin account can grant and revoke burnable role to an account', async function () { - // Admin grants burn role : success - let result = await hasRole( - BURN_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - expect(result).to.equals(false) - - await grantRole( - BURN_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - - result = await hasRole( - BURN_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - expect(result).to.equals(true) - - // Admin revokes burn role : success - await revokeRole( - BURN_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - result = await hasRole( - BURN_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - expect(result).to.equals(false) - }) + await grantRole( + BURN_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) - it('Non Admin account can not grant burnable role to an account', async function () { - // Non Admin grants burn role : fail - await expect( - grantRole( + result = await hasRole( BURN_ROLE, proxyAddress, - nonOperatorClient, + operatorClient, nonOperatorAccount, nonOperatorIsE25519 ) - ).to.eventually.be.rejectedWith(Error) - }) + expect(result).to.equals(true) - it('Non Admin account can not revoke burnable role to an account', async function () { - // Non Admin revokes burn role : fail - await grantRole( - BURN_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - await expect( - revokeRole( + // Admin revokes burn role : success + await revokeRole( BURN_ROLE, proxyAddress, - nonOperatorClient, + operatorClient, nonOperatorAccount, nonOperatorIsE25519 ) - ).to.eventually.be.rejectedWith(Error) - - //Reset status - await revokeRole( - BURN_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - }) + result = await hasRole( + BURN_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + expect(result).to.equals(false) + }) + + it('Non Admin account can not grant burnable role to an account', async function () { + // Non Admin grants burn role : fail + await expect( + grantRole( + BURN_ROLE, + proxyAddress, + nonOperatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + ).to.eventually.be.rejectedWith(Error) + }) + + it('Non Admin account can not revoke burnable role to an account', async function () { + // Non Admin revokes burn role : fail + await grantRole( + BURN_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + await expect( + revokeRole( + BURN_ROLE, + proxyAddress, + nonOperatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + ).to.eventually.be.rejectedWith(Error) + + //Reset status + await revokeRole( + BURN_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + }) - it('Can burn 10 tokens from the treasury account having 100 tokens', async function () { - const tokensToBurn = INIT_SUPPLY.div(10) + it('Can burn 10 tokens from the treasury account having 100 tokens', async function () { + const tokensToBurn = INIT_SUPPLY.div(10) - // Get the initial total supply and treasury account's balanceOf - const initialTotalSupply = await getTotalSupply( - proxyAddress, - operatorClient - ) + // Get the initial total supply and treasury account's balanceOf + const initialTotalSupply = await getTotalSupply( + proxyAddress, + operatorClient + ) - // burn some tokens - await Burn(proxyAddress, tokensToBurn, operatorClient) + // burn some tokens + await Burn(proxyAddress, tokensToBurn, operatorClient) - // check new total supply and balance of treasury account : success - const finalTotalSupply = await getTotalSupply( - proxyAddress, - operatorClient - ) - const expectedTotalSupply = initialTotalSupply.sub(tokensToBurn) + // check new total supply and balance of treasury account : success + const finalTotalSupply = await getTotalSupply( + proxyAddress, + operatorClient + ) + const expectedTotalSupply = initialTotalSupply.sub(tokensToBurn) - expect(finalTotalSupply.toString()).to.equals( - expectedTotalSupply.toString() - ) - }) + expect(finalTotalSupply.toString()).to.equals( + expectedTotalSupply.toString() + ) + }) - it('Cannot burn more tokens than the treasury account has', async function () { - // Retrieve original total supply - const currentTotalSupply = await getTotalSupply( - proxyAddress, - operatorClient - ) - - // burn more tokens than original total supply : fail - await expect( - Burn(proxyAddress, currentTotalSupply.add(1), operatorClient) - ).to.eventually.be.rejectedWith(Error) - }) + it('Cannot burn more tokens than the treasury account has', async function () { + // Retrieve original total supply + const currentTotalSupply = await getTotalSupply( + proxyAddress, + operatorClient + ) - it('User without burn role cannot burn tokens', async function () { - // Account without burn role, burns tokens : fail - await expect( - Burn(proxyAddress, BigNumber.from(1), nonOperatorClient) - ).to.eventually.be.rejectedWith(Error) - }) + // burn more tokens than original total supply : fail + await expect( + Burn(proxyAddress, currentTotalSupply.add(1), operatorClient) + ).to.eventually.be.rejectedWith(Error) + }) + + it('User without burn role cannot burn tokens', async function () { + // Account without burn role, burns tokens : fail + await expect( + Burn(proxyAddress, BigNumber.from(1), nonOperatorClient) + ).to.eventually.be.rejectedWith(Error) + }) - it('User with granted burn role can burn tokens', async function () { - const tokensToBurn = BigNumber.from(1) - - // Retrieve original total supply - const initialTotalSupply = await getTotalSupply( - proxyAddress, - operatorClient - ) - - // Grant burn role to account - await grantRole( - BURN_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - - // Burn tokens with newly granted account - await Burn(proxyAddress, tokensToBurn, nonOperatorClient) - - // Check final total supply and treasury account's balanceOf : success - const finalTotalSupply = await getTotalSupply( - proxyAddress, - operatorClient - ) - const expectedTotalSupply = initialTotalSupply.sub(tokensToBurn) - - expect(finalTotalSupply.toString()).to.equals( - expectedTotalSupply.toString() - ) + it('User with granted burn role can burn tokens', async function () { + const tokensToBurn = BigNumber.from(1) + + // Retrieve original total supply + const initialTotalSupply = await getTotalSupply( + proxyAddress, + operatorClient + ) + + // Grant burn role to account + await grantRole( + BURN_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + + // Burn tokens with newly granted account + await Burn(proxyAddress, tokensToBurn, nonOperatorClient) + + // Check final total supply and treasury account's balanceOf : success + const finalTotalSupply = await getTotalSupply( + proxyAddress, + operatorClient + ) + const expectedTotalSupply = initialTotalSupply.sub(tokensToBurn) + + expect(finalTotalSupply.toString()).to.equals( + expectedTotalSupply.toString() + ) + }) }) -}) +} diff --git a/contracts/test/freezable.ts b/contracts/test/freezable.ts index 27b56b656..d2794f26e 100644 --- a/contracts/test/freezable.ts +++ b/contracts/test/freezable.ts @@ -1,7 +1,6 @@ import '@hashgraph/hardhat-hethers' import '@hashgraph/sdk' import { BigNumber } from 'ethers' -import { deployContractsWithSDK } from '../scripts/deploy' import { freeze, getBalanceOf, @@ -16,21 +15,13 @@ import { ContractId } from '@hashgraph/sdk' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' import { - INIT_SUPPLY, - MAX_SUPPLY, nonOperatorAccount, nonOperatorClient, nonOperatorIsE25519, operatorAccount, operatorClient, operatorIsE25519, - operatorPriKey, - operatorPubKey, - TOKEN_DECIMALS, TOKEN_FACTOR, - TOKEN_MEMO, - TOKEN_NAME, - TOKEN_SYMBOL, } from './shared/utils' chai.use(chaiAsPromised) @@ -38,246 +29,229 @@ const expect = chai.expect let proxyAddress: ContractId -describe('Freeze Tests', function () { - before(async function () { - // Deploy Token using Client - const [result] = await Promise.all([ - deployContractsWithSDK({ - name: TOKEN_NAME, - symbol: TOKEN_SYMBOL, - decimals: TOKEN_DECIMALS, - initialSupply: INIT_SUPPLY.toString(), - maxSupply: MAX_SUPPLY.toString(), - memo: TOKEN_MEMO, - account: operatorAccount, - privateKey: operatorPriKey, - publicKey: operatorPubKey, - isED25519Type: operatorIsE25519, - initialAmountDataFeed: INIT_SUPPLY.add( - BigNumber.from('100000') - ).toString(), - }), - ]) +export const freezable = (deployedContracts: ContractId[]) => { + describe('Freeze Tests', function () { + before(async function () { + proxyAddress = deployedContracts[0] + }) - proxyAddress = result[0] - }) + it('Admin account can grant and revoke freeze role to an account', async function () { + // Admin grants freeze role : success + let result = await hasRole( + FREEZE_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + expect(result).to.equals(false) - it('Admin account can grant and revoke freeze role to an account', async function () { - // Admin grants freeze role : success - let result = await hasRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - expect(result).to.equals(false) + await grantRole( + FREEZE_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) - await grantRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) + result = await hasRole( + FREEZE_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + expect(result).to.equals(true) - result = await hasRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - expect(result).to.equals(true) + // Admin revokes freeze role : success + await revokeRole( + FREEZE_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + result = await hasRole( + FREEZE_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + expect(result).to.equals(false) + }) - // Admin revokes freeze role : success - await revokeRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - result = await hasRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - expect(result).to.equals(false) - }) + it('Non Admin account can not grant freeze role to an account', async function () { + // Non Admin grants freeze role : fail + await expect( + grantRole( + FREEZE_ROLE, + proxyAddress, + nonOperatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + ).to.eventually.be.rejectedWith(Error) + }) - it('Non Admin account can not grant freeze role to an account', async function () { - // Non Admin grants freeze role : fail - await expect( - grantRole( + it('Non Admin account can not revoke freeze role to an account', async function () { + // Non Admin revokes freeze role : fail + await grantRole( FREEZE_ROLE, proxyAddress, - nonOperatorClient, + operatorClient, nonOperatorAccount, nonOperatorIsE25519 ) - ).to.eventually.be.rejectedWith(Error) - }) + await expect( + revokeRole( + FREEZE_ROLE, + proxyAddress, + nonOperatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + ).to.eventually.be.rejectedWith(Error) - it('Non Admin account can not revoke freeze role to an account', async function () { - // Non Admin revokes freeze role : fail - await grantRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - await expect( - revokeRole( + //Reset status + await revokeRole( FREEZE_ROLE, proxyAddress, - nonOperatorClient, + operatorClient, nonOperatorAccount, nonOperatorIsE25519 ) - ).to.eventually.be.rejectedWith(Error) + }) - //Reset status - await revokeRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - }) + it("An account without freeze role can't freeze transfers of the token for the account", async function () { + await expect( + freeze( + proxyAddress, + nonOperatorClient, + operatorAccount, + operatorIsE25519 + ) + ).to.eventually.be.rejectedWith(Error) + }) - it("An account without freeze role can't freeze transfers of the token for the account", async function () { - await expect( - freeze( + it("An account without freeze role can't unfreeze transfers of the token for the account", async function () { + await expect( + unfreeze( + proxyAddress, + nonOperatorClient, + operatorAccount, + operatorIsE25519 + ) + ).to.eventually.be.rejectedWith(Error) + }) + + it('An account with freeze role can freeze transfers of the token for the account', async function () { + await grantRole( + FREEZE_ROLE, proxyAddress, - nonOperatorClient, - operatorAccount, - operatorIsE25519 + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 ) - ).to.eventually.be.rejectedWith(Error) - }) - it("An account without freeze role can't unfreeze transfers of the token for the account", async function () { - await expect( - unfreeze( + await expect( + freeze( + proxyAddress, + nonOperatorClient, + operatorAccount, + operatorIsE25519 + ) + ).not.to.eventually.be.rejectedWith(Error) + + //Reset status + await unfreeze( proxyAddress, nonOperatorClient, operatorAccount, operatorIsE25519 ) - ).to.eventually.be.rejectedWith(Error) - }) - - it('An account with freeze role can freeze transfers of the token for the account', async function () { - await grantRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) + await revokeRole( + FREEZE_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + }) - await expect( - freeze( + it('An account with freeze role can unfreeze transfers of the token for the account', async function () { + await grantRole( + FREEZE_ROLE, proxyAddress, - nonOperatorClient, - operatorAccount, - operatorIsE25519 + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 ) - ).not.to.eventually.be.rejectedWith(Error) - //Reset status - await unfreeze( - proxyAddress, - nonOperatorClient, - operatorAccount, - operatorIsE25519 - ) - await revokeRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - }) + await expect( + unfreeze( + proxyAddress, + nonOperatorClient, + operatorAccount, + operatorIsE25519 + ) + ).not.to.eventually.be.rejectedWith(Error) + + //Reset status + await revokeRole( + FREEZE_ROLE, + proxyAddress, + operatorClient, + nonOperatorAccount, + nonOperatorIsE25519 + ) + }) - it('An account with freeze role can unfreeze transfers of the token for the account', async function () { - await grantRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) + it('When freezing transfers of the token for the account a rescue operation can not be performed', async function () { + const AmountToRescue = BigNumber.from(1).mul(TOKEN_FACTOR) - await expect( - unfreeze( + await freeze( proxyAddress, - nonOperatorClient, + operatorClient, operatorAccount, operatorIsE25519 ) - ).not.to.eventually.be.rejectedWith(Error) + await expect( + rescue(proxyAddress, AmountToRescue, operatorClient) + ).to.eventually.be.rejectedWith(Error) - //Reset status - await revokeRole( - FREEZE_ROLE, - proxyAddress, - operatorClient, - nonOperatorAccount, - nonOperatorIsE25519 - ) - }) - - it('When freezing transfers of the token for the account a rescue operation can not be performed', async function () { - const AmountToRescue = BigNumber.from(1).mul(TOKEN_FACTOR) - - await freeze( - proxyAddress, - operatorClient, - operatorAccount, - operatorIsE25519 - ) - await expect( - rescue(proxyAddress, AmountToRescue, operatorClient) - ).to.eventually.be.rejectedWith(Error) - - //Reset status - await unfreeze( - proxyAddress, - operatorClient, - operatorAccount, - operatorIsE25519 - ) - }) + //Reset status + await unfreeze( + proxyAddress, + operatorClient, + operatorAccount, + operatorIsE25519 + ) + }) - it('When unfreezing transfers of the token for the account a rescue operation can be performed', async function () { - const AmountToRescue = BigNumber.from(1).mul(TOKEN_FACTOR) + it('When unfreezing transfers of the token for the account a rescue operation can be performed', async function () { + const AmountToRescue = BigNumber.from(1).mul(TOKEN_FACTOR) - await freeze( - proxyAddress, - operatorClient, - operatorAccount, - operatorIsE25519 - ) - await unfreeze( - proxyAddress, - operatorClient, - operatorAccount, - operatorIsE25519 - ) - await rescue(proxyAddress, AmountToRescue, operatorClient) - const balance = await getBalanceOf( - proxyAddress, - operatorClient, - operatorAccount, - operatorIsE25519 - ) - expect(balance.toString()).to.equals(AmountToRescue.toString()) + await freeze( + proxyAddress, + operatorClient, + operatorAccount, + operatorIsE25519 + ) + await unfreeze( + proxyAddress, + operatorClient, + operatorAccount, + operatorIsE25519 + ) + await rescue(proxyAddress, AmountToRescue, operatorClient) + const balance = await getBalanceOf( + proxyAddress, + operatorClient, + operatorAccount, + operatorIsE25519 + ) + expect(balance.toString()).to.equals(AmountToRescue.toString()) + }) }) -}) +} diff --git a/contracts/test/stableCoinStudio.ts b/contracts/test/stableCoinStudio.ts new file mode 100644 index 000000000..2b292aefc --- /dev/null +++ b/contracts/test/stableCoinStudio.ts @@ -0,0 +1,11 @@ +import {burnable} from "./burnable"; +import {freezable} from "./freezable"; +import { ContractId } from '@hashgraph/sdk' + +describe('Stable Coin Studio test suite', () => { + const deployedContractsForBurnableAndFreezable: ContractId[] = []; + + burnable(deployedContractsForBurnableAndFreezable); + freezable(deployedContractsForBurnableAndFreezable); + +});