Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: whitelist tf hooks #314

Merged
merged 26 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
84383a4
add tokenfactory params tests
jcompagni10 Jun 20, 2024
d6dbf48
fix tests
jcompagni10 Jun 21, 2024
924835f
lint
jcompagni10 Jun 21, 2024
0ea9681
disable setBeforeSendHook tests
jcompagni10 Jun 21, 2024
1a129e5
lint
jcompagni10 Jun 21, 2024
df4229c
Merge branch 'feat/whitelist-tf-hooks-core-changes' into feat/whiteli…
jcompagni10 Jun 21, 2024
82cafb0
lint
jcompagni10 Jun 21, 2024
84b8f5b
fix incorrect params in TF test
jcompagni10 Jun 21, 2024
e128aa2
update neutron jsplus dep
jcompagni10 Jun 25, 2024
f2022e8
lint
jcompagni10 Jun 25, 2024
2205329
whitelist denom hooks for tf tests
jcompagni10 Jun 29, 2024
16e0502
misc cleanup
jcompagni10 Jun 29, 2024
02686cc
add wait for timelock proposal
jcompagni10 Jun 29, 2024
af21a6a
lint
jcompagni10 Jun 29, 2024
48b0fa2
change tf proposal title and description
jcompagni10 Jul 1, 2024
6b33cec
add test for set non-whitelisted hook failure
jcompagni10 Jul 1, 2024
153302e
specify neutronjsplus dep with hash
jcompagni10 Jul 2, 2024
7ed5175
cleanup test for failing whitelist and change subdao voting period
jcompagni10 Jul 2, 2024
b2be1b5
fix whitelist proposal
jcompagni10 Jul 2, 2024
ca9a9ea
lint
jcompagni10 Jul 2, 2024
ace269e
remove temp fee_collector_address
jcompagni10 Jul 2, 2024
2b5fc0c
attempt to fix njs problem
quasisamurai Jul 3, 2024
2ab1175
another attempt to fix dependency
quasisamurai Jul 3, 2024
bd5a28b
run tokenfactory tests in_band
jcompagni10 Jul 3, 2024
0645791
fix tests
pr0n00gler Jul 4, 2024
8e7c707
upd neutronjplus commit
pr0n00gler Jul 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@cosmos-client/core": "^0.47.4",
"@cosmos-client/cosmwasm": "^0.40.3",
"@cosmos-client/ibc": "^1.2.1",
"@neutron-org/neutronjsplus": "0.4.1",
"@neutron-org/neutronjsplus": "neutron-org/neutronjsplus#feat/whitelist-tf-hooks",
"@types/lodash": "^4.14.182",
"@types/long": "^5.0.0",
"axios": "^0.27.2",
Expand Down Expand Up @@ -93,4 +93,4 @@
"engines": {
"node": ">=16.0 <17"
}
}
}
127 changes: 121 additions & 6 deletions src/testcases/parallel/tokenfactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
NEUTRON_DENOM,
getEventAttribute,
} from '@neutron-org/neutronjsplus/dist/cosmos';
import cosmosclient from '@cosmos-client/core';
import { TestStateLocalCosmosTestNet } from '@neutron-org/neutronjsplus';
import { NeutronContract, Wallet } from '@neutron-org/neutronjsplus/dist/types';
import {
Expand All @@ -13,19 +14,70 @@ import {
msgCreateDenom,
msgMintDenom,
msgSetBeforeSendHook,
getBeforeSendHook,
getDenomsFromCreator,
checkTokenfactoryParams,
getAuthorityMetadata,
getBeforeSendHook,
} from '@neutron-org/neutronjsplus/dist/tokenfactory';
import {
Dao,
DaoMember,
getDaoContracts,
setupSubDaoTimelockSet,
} from '@neutron-org/neutronjsplus/dist/dao';
import { updateTokenfactoryParamsProposal } from '@neutron-org/neutronjsplus/dist/proposal';
import { waitSeconds } from '@neutron-org/neutronjsplus/dist/wait';

const config = require('../../config.json');

async function whitelistTokenfactoryHook(
neutronChain: CosmosWrapper,
subDao: Dao,
subdaoMember1: DaoMember,
codeID: number,
denomCreator: string,
) {
const chainManagerAddress = (await neutronChain.getChainAdmins())[0];
const proposalId = await subdaoMember1.submitUpdateParamsTokenfactoryProposal(
chainManagerAddress,
'whitelist proposal',
'whitelist tokenfactory hook. Will pass',
updateTokenfactoryParamsProposal({
denom_creation_fee: [],
denom_creation_gas_consume: 0,
fee_collector_address: '',
whitelisted_hooks: [
{
code_id: codeID,
denom_creator: denomCreator,
},
],
}),
'1000',
);

let timelockedProp = await subdaoMember1.supportAndExecuteProposal(
proposalId,
);
await waitSeconds(10);

await subdaoMember1.executeTimelockedProposal(proposalId);
timelockedProp = await subDao.getTimelockedProposal(proposalId);
expect(timelockedProp.id).toEqual(proposalId);
expect(timelockedProp.status).toEqual('executed');
}

describe('Neutron / Tokenfactory', () => {
let testState: TestStateLocalCosmosTestNet;
let neutronChain: CosmosWrapper;
let neutronAccount: WalletWrapper;
let ownerWallet: Wallet;
let subDao: Dao;
let mainDao: Dao;
let subdaoMember1: DaoMember;
let mainDaoMember: DaoMember;
let securityDaoWallet: Wallet;
let securityDaoAddr: cosmosclient.AccAddress | cosmosclient.ValAddress;

beforeAll(async () => {
testState = new TestStateLocalCosmosTestNet(config);
Expand All @@ -37,6 +89,56 @@ describe('Neutron / Tokenfactory', () => {
NEUTRON_DENOM,
);
neutronAccount = new WalletWrapper(neutronChain, ownerWallet);

// Setup subdao with update tokenfactory params
const daoCoreAddress = await neutronChain.getNeutronDAOCore();
const daoContracts = await getDaoContracts(neutronChain, daoCoreAddress);
securityDaoWallet = testState.wallets.qaNeutronThree.genQaWal1;
securityDaoAddr = securityDaoWallet.address;

mainDao = new Dao(neutronChain, daoContracts);
mainDaoMember = new DaoMember(neutronAccount, mainDao);
await mainDaoMember.bondFunds('10000');

subDao = await setupSubDaoTimelockSet(
neutronAccount,
mainDao.contracts.core.address,
securityDaoAddr.toString(),
true,
);

subdaoMember1 = new DaoMember(neutronAccount, subDao);

const chainManagerAddress = (await neutronChain.getChainAdmins())[0];
const proposalId =
await mainDaoMember.submitAddChainManagerStrategyProposal(
chainManagerAddress,
'Proposal #1',
'Add strategy proposal. It will pass',
{
add_strategy: {
address: subDao.contracts.core.address,
strategy: {
allow_only: [
{
update_tokenfactory_params_permission: {
denom_creation_fee: true,
denom_creation_gas_consume: true,
fee_collector_address: true,
whitelisted_hooks: true,
},
},
],
},
},
},
'1000',
);

await mainDaoMember.voteYes(proposalId);
await mainDao.checkPassedProposal(proposalId);
await waitSeconds(10);
await mainDaoMember.executeProposalWithAttempts(proposalId);
});

test('tokenfactory module is added', async () => {
Expand Down Expand Up @@ -245,6 +347,14 @@ describe('Neutron / Tokenfactory', () => {
expect(queryTrack.track.received).toEqual(false);
expect(queryBlock.block.received).toEqual(false);

await whitelistTokenfactoryHook(
neutronChain,
subDao,
subdaoMember1,
codeId,
ownerWallet.address.toString(),
);

await msgSetBeforeSendHook(
neutronAccount,
ownerWallet.address.toString(),
Expand Down Expand Up @@ -298,11 +408,10 @@ describe('Neutron / Tokenfactory', () => {
let denom: string;
let amount = 10000000;
const toBurn = 1000000;
let codeId;

test('setup contract', async () => {
const codeId = await neutronAccount.storeWasm(
NeutronContract.TOKENFACTORY,
);
codeId = await neutronAccount.storeWasm(NeutronContract.TOKENFACTORY);
expect(codeId).toBeGreaterThan(0);

const res = await neutronAccount.instantiateContract(
Expand All @@ -327,7 +436,6 @@ describe('Neutron / Tokenfactory', () => {
},
}),
);
console.log(JSON.stringify(res.events));
denom = res.events
?.find((event) => event.type == 'create_denom')
?.attributes?.find(
Expand Down Expand Up @@ -429,8 +537,15 @@ describe('Neutron / Tokenfactory', () => {
);
expect(res.admin).toEqual(contractAddress);
});

test('set_before_send_hook', async () => {
await whitelistTokenfactoryHook(
neutronChain,
subDao,
subdaoMember1,
codeId,
contractAddress,
);

await neutronAccount.executeContract(
contractAddress,
JSON.stringify({
Expand Down
83 changes: 76 additions & 7 deletions src/testcases/run_in_band/chain_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
import { Wallet } from '@neutron-org/neutronjsplus/dist/types';
import cosmosclient from '@cosmos-client/core';
import { waitSeconds } from '@neutron-org/neutronjsplus/dist/wait';
import { updateCronParamsProposal } from '@neutron-org/neutronjsplus/dist/proposal';
import {
updateCronParamsProposal,
updateTokenfactoryParamsProposal,
} from '@neutron-org/neutronjsplus/dist/proposal';

import config from '../../config.json';

Expand Down Expand Up @@ -128,7 +131,7 @@ describe('Neutron / Chain Manager', () => {
});
});

describe('Add an ALLOW_ONLY strategy (Cron module parameter updates, legacy param changes)', () => {
describe('Add an ALLOW_ONLY strategy (Cron module parameter updates, Tokenfactory module parameter updates, legacy param changes)', () => {
let proposalId: number;
test('create proposal', async () => {
const chainManagerAddress = (await neutronChain.getChainAdmins())[0];
Expand All @@ -152,11 +155,17 @@ describe('Neutron / Chain Manager', () => {
},
},
{
update_params_permission: {
cron_update_params_permission: {
security_address: true,
limit: true,
},
update_cron_params_permission: {
security_address: true,
limit: true,
},
},
{
update_tokenfactory_params_permission: {
denom_creation_fee: true,
denom_creation_gas_consume: true,
fee_collector_address: true,
whitelisted_hooks: true,
},
},
],
Expand Down Expand Up @@ -219,4 +228,64 @@ describe('Neutron / Chain Manager', () => {
expect(cronParams.params.limit).toEqual('42');
});
});

describe('ALLOW_ONLY: change TOKENFACTORY parameters', () => {
let proposalId: number;
beforeAll(async () => {
const chainManagerAddress = (await neutronChain.getChainAdmins())[0];
proposalId = await subdaoMember1.submitUpdateParamsTokenfactoryProposal(
chainManagerAddress,
'Proposal #2',
'Cron update params proposal. Will pass',
updateTokenfactoryParamsProposal({
denom_creation_fee: [{ denom: 'untrn', amount: '1' }],
denom_creation_gas_consume: 20,
fee_collector_address:
'neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2',
whitelisted_hooks: [
{
code_id: 1,
denom_creator: 'neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2',
},
],
}),
'1000',
);

const timelockedProp = await subdaoMember1.supportAndExecuteProposal(
proposalId,
);

expect(timelockedProp.id).toEqual(proposalId);
expect(timelockedProp.status).toEqual('timelocked');
expect(timelockedProp.msgs).toHaveLength(1);
});

test('execute timelocked: success', async () => {
await waitSeconds(10);

await subdaoMember1.executeTimelockedProposal(proposalId);
const timelockedProp = await subDao.getTimelockedProposal(proposalId);
expect(timelockedProp.id).toEqual(proposalId);
expect(timelockedProp.status).toEqual('executed');
expect(timelockedProp.msgs).toHaveLength(1);

const tokenfactoryParams = await neutronChain.queryTokenfactoryParams();
expect(tokenfactoryParams.params.denom_creation_fee).toEqual([
{ denom: 'untrn', amount: '1' },
]);
expect(tokenfactoryParams.params.denom_creation_gas_consume).toEqual(
'20',
);
expect(tokenfactoryParams.params.fee_collector_address).toEqual(
'neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2',
);
expect(tokenfactoryParams.params.whitelisted_hooks).toEqual([
{
code_id: '1',
denom_creator: 'neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2',
},
]);
});
});
});
11 changes: 8 additions & 3 deletions src/testcases/run_in_band/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Neutron / Parameters', () => {
'Tokenfactory params proposal',
updateTokenfacoryParamsProposal({
fee_collector_address: await neutronChain.getNeutronDAOCore(),
denom_creation_fee: null,
denom_creation_fee: [{ denom: 'untrn', amount: '1' }],
denom_creation_gas_consume: 100000,
}),
'1000',
Expand All @@ -156,13 +156,18 @@ describe('Neutron / Parameters', () => {
test('check if params changed after proposal execution', async () => {
const paramsAfter = await neutronChain.queryTokenfactoryParams();

expect(paramsAfter.params.denom_creation_fee).toEqual(
expect(paramsAfter.params.denom_creation_fee).not.toEqual(
paramsBefore.params.denom_creation_fee,
);
expect(paramsAfter.params.denom_creation_gas_consume).not.toEqual(
paramsBefore.params.denom_creation_gas_consume,
);
expect(paramsAfter.params.denom_creation_fee).toHaveLength(0);
expect(paramsAfter.params.denom_creation_fee).toEqual([
{
denom: 'untrn',
amount: '1',
},
]);
expect(paramsAfter.params.denom_creation_gas_consume).toEqual('100000');
});
});
Expand Down
7 changes: 3 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1568,10 +1568,9 @@
resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-5.50.0.tgz#29c6419e8379d496ab6d0426eadf3c4d100cd186"
integrity sha512-swKHYCOZUGyVt4ge0u8a7AwNcA//h4nx5wIi0sruGye1IJ5Cva0GyK9L2/WdX+kWVTKp92ZiEo1df31lrWGPgA==

"@neutron-org/[email protected]":
version "0.4.1"
resolved "https://registry.yarnpkg.com/@neutron-org/neutronjsplus/-/neutronjsplus-0.4.1.tgz#5e7b6e8f0ea63873719ae9011103c297c3eca209"
integrity sha512-CyRAxai2Pk8tpU+0cUEGGchwwf2wBa8wfCPWJRf07PRTvBJ06sEYMfJqW0kdUtLuBc9tqEt4DD2IGfGkOrVwyg==
"@neutron-org/neutronjsplus@neutron-org/neutronjsplus#feat/whitelist-tf-hooks":
version "0.4.0-rc19"
resolved "https://codeload.github.com/neutron-org/neutronjsplus/tar.gz/891da6c41e0801fa8e5422d166c835df5f41eef8"
dependencies:
"@bufbuild/protobuf" "^1.4.2"
"@cosmos-client/core" "^0.47.4"
Expand Down
Loading