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 21 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#bcad3b0dc674ad54a63556863515e6832cebed5d",
"@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"
}
}
}
205 changes: 198 additions & 7 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,69 @@ 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 TF hook 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');
Comment on lines +59 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't this (speeded up?) approach work? I can see that you added it and then removed in the latest commits
image

}

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 +88,100 @@ 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];

// shorten subdao voting period
const currentOverruleProposalConfig = await neutronChain.queryContract(
mainDao.contracts.proposals['overrule'].address,
{
config: {},
},
);
currentOverruleProposalConfig['max_voting_period']['time'] = 5;
const proposalId = await mainDaoMember.submitSingleChoiceProposal(
'Proposal',
'Update the max voting period. It will pass',
[
{
wasm: {
execute: {
contract_addr: mainDao.contracts.proposals['overrule'].address,
msg: Buffer.from(
JSON.stringify({
update_config: {
threshold: currentOverruleProposalConfig['threshold'],
max_voting_period:
currentOverruleProposalConfig['max_voting_period'],
allow_revoting:
currentOverruleProposalConfig['allow_revoting'],
dao: currentOverruleProposalConfig['dao'],
close_proposal_on_execution_failure:
currentOverruleProposalConfig[
'close_proposal_on_execution_failure'
],
},
}),
).toString('base64'),
funds: [],
},
},
},
],
'1000',
);
await mainDaoMember.voteYes(proposalId);
await mainDao.checkPassedProposal(proposalId);
await mainDaoMember.executeProposalWithAttempts(proposalId);

const proposalId2 =
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(proposalId2);
await mainDao.checkPassedProposal(proposalId2);
await waitSeconds(10);
await mainDaoMember.executeProposalWithAttempts(proposalId2);
});

test('tokenfactory module is added', async () => {
Expand Down Expand Up @@ -182,7 +327,7 @@ describe('Neutron / Tokenfactory', () => {

expect(balanceAfter).toEqual(9900);
});
test('create denom, set before send hook', async () => {
test('set non-whitlisted hook fails', async () => {
const codeId = await neutronAccount.storeWasm(
NeutronContract.BEFORE_SEND_HOOK_TEST,
);
Expand All @@ -197,6 +342,39 @@ describe('Neutron / Tokenfactory', () => {

const denom = `test5`;

const data = await msgCreateDenom(
neutronAccount,
ownerWallet.address.toString(),
denom,
);
const newTokenDenom = getEventAttribute(
(data as any).events,
'create_denom',
'new_token_denom',
);
const res2 = await msgSetBeforeSendHook(
neutronAccount,
ownerWallet.address.toString(),
newTokenDenom,
contractAddress,
);
expect(res2.code).toEqual(14); // "beforeSendHook is not whitelisted"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's good enough to check the code, but just FYI for the future: a more convenient IMO way to check errors is by the error message e.g. like here (or actually in many other places in our tests)

await expect(
tgeWallets[v].executeContract(
tgeMain.contracts.lockdrop,
JSON.stringify({
claim_rewards_and_optionally_unlock: {
pool_type: 'ATOM',
duration: 1,
withdraw_lp_stake: false,
},
}),
),
).rejects.toThrowError(/LockupInfoV1 not found/);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be mistaken but the way msgSetBeforeSendHook is called I can't use rejects

});
test('create denom, set before send hook', async () => {
const codeId = await neutronAccount.storeWasm(
NeutronContract.BEFORE_SEND_HOOK_TEST,
);
expect(codeId).toBeGreaterThan(0);

const res = await neutronAccount.instantiateContract(
codeId,
'{}',
'before_send_hook_test',
);
const contractAddress = res[0]._contract_address;

const denom = `test6`;

const data = await msgCreateDenom(
neutronAccount,
ownerWallet.address.toString(),
Expand Down Expand Up @@ -245,6 +423,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 +484,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 +512,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 +613,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
Loading
Loading