From 3bc3582400611b0ad91fd92409fc38410f954cae Mon Sep 17 00:00:00 2001 From: Constantin Dogaru Date: Fri, 25 Mar 2022 10:44:52 +0200 Subject: [PATCH 1/5] update near-workspaces-ava package --- sputnikdao2/tests-ava/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sputnikdao2/tests-ava/package.json b/sputnikdao2/tests-ava/package.json index 7bb8f51ac..9ea2629b8 100644 --- a/sputnikdao2/tests-ava/package.json +++ b/sputnikdao2/tests-ava/package.json @@ -6,7 +6,7 @@ "test:testnet": "near-workspaces-ava --config ./ava.testnet.config.cjs" }, "devDependencies": { - "near-workspaces-ava": "1.0.0", + "near-workspaces-ava": "^1.1.0", "prettier": "^2.5.1" } } From 61f2ca2c66a3ce5c6452857771f6954aa9fca03f Mon Sep 17 00:00:00 2001 From: Constantin Dogaru Date: Fri, 25 Mar 2022 10:53:42 +0200 Subject: [PATCH 2/5] fix the proposals.ava.ts file --- sputnikdao2/tests-ava/__tests__/proposals.ava.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sputnikdao2/tests-ava/__tests__/proposals.ava.ts b/sputnikdao2/tests-ava/__tests__/proposals.ava.ts index 87700f5e6..3166b2b3e 100644 --- a/sputnikdao2/tests-ava/__tests__/proposals.ava.ts +++ b/sputnikdao2/tests-ava/__tests__/proposals.ava.ts @@ -36,7 +36,7 @@ workspace.test( //Try adding a proposal with 0.999... near let err = await captureError( async () => - await alice.call_raw( + await alice.call( dao, 'add_proposal', { From ddfbcce5807f7686569afbaf8c78be1e7a70774f Mon Sep 17 00:00:00 2001 From: Constantin Dogaru Date: Fri, 25 Mar 2022 12:36:53 +0200 Subject: [PATCH 3/5] replace createTransaction with call --- sputnikdao2/tests-ava/__tests__/lib.ava.ts | 112 ++++++++----------- sputnikdao2/tests-ava/__tests__/views.ava.ts | 13 +-- 2 files changed, 50 insertions(+), 75 deletions(-) diff --git a/sputnikdao2/tests-ava/__tests__/lib.ava.ts b/sputnikdao2/tests-ava/__tests__/lib.ava.ts index 111373438..7bb7cc9dd 100644 --- a/sputnikdao2/tests-ava/__tests__/lib.ava.ts +++ b/sputnikdao2/tests-ava/__tests__/lib.ava.ts @@ -62,41 +62,36 @@ workspaceWithFactory.test( ]); const hash = await factory.view('get_default_code_hash', {}); - const result = await root - .createTransaction('testdao.factory.test.near') - .functionCall( - 'add_proposal', - { - proposal: { - description: 'proposal to test', - kind: { - UpgradeSelf: { - hash: hash, - }, + const proposalId: number = await root.call( + 'testdao.factory.test.near', + 'add_proposal', + { + proposal: { + description: 'proposal to test', + kind: { + UpgradeSelf: { + hash: hash, }, }, }, - { - attachedDeposit: toYocto('1'), - }, - ) - .signAndSend(); - const proposalId = result.parseResult(); + }, + { + attachedDeposit: toYocto('1'), + }, + ); test.is(proposalId, 0); - await root - .createTransaction('testdao.factory.test.near') - .functionCall( - 'act_proposal', - { - id: proposalId, - action: 'VoteApprove', - }, - { - gas: tGas(300), - }, - ) - .signAndSend(); + await root.call( + 'testdao.factory.test.near', + 'act_proposal', + { + id: proposalId, + action: 'VoteApprove', + }, + { + gas: tGas(300), + }, + ); }, ); @@ -107,13 +102,10 @@ workspaceWithoutInit.test( // NOT INITIALIZED let err = await captureError(async () => - root - .createTransaction(dao) - .functionCall('store_blob', DAO_WASM_BYTES, { - attachedDeposit: toYocto('200'), - gas: tGas(300), - }) - .signAndSend(), + root.call(dao, 'store_blob', DAO_WASM_BYTES, { + attachedDeposit: toYocto('200'), + gas: tGas(300), + }), ); test.regex(err, /ERR_CONTRACT_IS_NOT_INITIALIZED/); @@ -122,48 +114,34 @@ workspaceWithoutInit.test( // not enough deposit err = await captureError(async () => - root - .createTransaction(dao) - .functionCall('store_blob', DAO_WASM_BYTES, { - attachedDeposit: toYocto('1'), - gas: tGas(300), - }) - .signAndSend(), + root.call(dao, 'store_blob', DAO_WASM_BYTES, { + attachedDeposit: toYocto('1'), + gas: tGas(300), + }), ); test.regex(err, /ERR_NOT_ENOUGH_DEPOSIT/); - await root - .createTransaction(dao) - .functionCall('store_blob', DAO_WASM_BYTES, { - attachedDeposit: toYocto('200'), - gas: tGas(300), - }) - .signAndSend(); + await root.call(dao, 'store_blob', DAO_WASM_BYTES, { + attachedDeposit: toYocto('200'), + gas: tGas(300), + }); // Already exists err = await captureError(async () => - root - .createTransaction(dao) - .functionCall('store_blob', DAO_WASM_BYTES, { - attachedDeposit: toYocto('200'), - gas: tGas(300), - }) - .signAndSend(), + root.call(dao, 'store_blob', DAO_WASM_BYTES, { + attachedDeposit: toYocto('200'), + gas: tGas(300), + }), ); test.regex(err, /ERR_ALREADY_EXISTS/); }, ); workspace.test('Remove blob', async (test, { root, dao, alice }) => { - const result = await root - .createTransaction(dao) - .functionCall('store_blob', DAO_WASM_BYTES, { - attachedDeposit: toYocto('200'), - gas: tGas(300), - }) - .signAndSend(); - - const hash = result.parseResult(); + const hash: String = await root.call(dao, 'store_blob', DAO_WASM_BYTES, { + attachedDeposit: toYocto('200'), + gas: tGas(300), + }); // fails if hash is wrong let err = await captureError(async () => diff --git a/sputnikdao2/tests-ava/__tests__/views.ava.ts b/sputnikdao2/tests-ava/__tests__/views.ava.ts index 1cd003ea7..5ba2ea957 100644 --- a/sputnikdao2/tests-ava/__tests__/views.ava.ts +++ b/sputnikdao2/tests-ava/__tests__/views.ava.ts @@ -113,14 +113,11 @@ workspace.test('View has_blob', async (test, { alice, root, dao }) => { const DAO_WASM_BYTES: Uint8Array = fs.readFileSync( '../res/sputnikdao2.wasm', ); - const result = await root - .createTransaction(dao) - .functionCall('store_blob', DAO_WASM_BYTES, { - attachedDeposit: toYocto('200'), - gas: tGas(300), - }) - .signAndSend(); - const hash = result.parseResult(); + const hash: String = await root.call(dao, 'store_blob', DAO_WASM_BYTES, { + attachedDeposit: toYocto('200'), + gas: tGas(300), + }); + test.true(await dao.view('has_blob', { hash: hash })); await root.call(dao, 'remove_blob', { hash: hash, From 6e4d3da19e8dcb65f4157551ca1eb7bf6e3488a6 Mon Sep 17 00:00:00 2001 From: Constantin Dogaru Date: Fri, 25 Mar 2022 12:45:38 +0200 Subject: [PATCH 4/5] finish replacing createtransaction with call --- .../tests-ava/__tests__/upgrade.ava.ts | 166 +++++++++--------- 1 file changed, 87 insertions(+), 79 deletions(-) diff --git a/sputnikdao2/tests-ava/__tests__/upgrade.ava.ts b/sputnikdao2/tests-ava/__tests__/upgrade.ava.ts index bce164803..bd039613a 100644 --- a/sputnikdao2/tests-ava/__tests__/upgrade.ava.ts +++ b/sputnikdao2/tests-ava/__tests__/upgrade.ava.ts @@ -49,11 +49,12 @@ workspaceWithFactory.test( const six_near = toYocto('6'); const default_code_hash = await factory.view('get_default_code_hash'); - let result = await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('get_last_proposal_id', {}, { gas: tGas(300) }) - .signAndSend(); - let proposalId = result.parseResult(); + let proposalId: number = await root.call( + 'upgradedao.factory.test.near', + 'get_last_proposal_id', + {}, + { gas: tGas(300) }, + ); test.is(proposalId, 0); const args = Buffer.from( @@ -80,26 +81,30 @@ workspaceWithFactory.test( }, }; - await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('add_proposal', proposal, { + await root.call( + 'upgradedao.factory.test.near', + 'add_proposal', + proposal, + { attachedDeposit: toYocto('1'), gas: tGas(300), - }) - .signAndSend(); + }, + ); - result = await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('get_last_proposal_id', {}, { gas: tGas(300) }) - .signAndSend(); - proposalId = result.parseResult(); + proposalId = await root.call( + 'upgradedao.factory.test.near', + 'get_last_proposal_id', + {}, + { gas: tGas(300) }, + ); test.is(proposalId, 1); - result = await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('get_proposal', { id: 0 }, { gas: tGas(300) }) - .signAndSend(); - let new_proposal = result.parseResult(); + let new_proposal: any = await root.call( + 'upgradedao.factory.test.near', + 'get_proposal', + { id: 0 }, + { gas: tGas(300) }, + ); test.log(new_proposal); test.is( @@ -114,20 +119,19 @@ workspaceWithFactory.test( `${factory.accountId}`, ); - await root - .createTransaction('upgradedao.factory.test.near') - .functionCall( - 'act_proposal', - { id: 0, action: 'VoteApprove' }, - { gas: tGas(300) }, - ) - .signAndSend(); + await root.call( + 'upgradedao.factory.test.near', + 'act_proposal', + { id: 0, action: 'VoteApprove' }, + { gas: tGas(300) }, + ); - result = await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('get_proposal', { id: 0 }, { gas: tGas(300) }) - .signAndSend(); - let passed_proposal_0 = result.parseResult(); + let passed_proposal_0: any = await root.call( + 'upgradedao.factory.test.near', + 'get_proposal', + { id: 0 }, + { gas: tGas(300) }, + ); test.log(passed_proposal_0); test.is(passed_proposal_0.status, 'Approved'); @@ -143,19 +147,22 @@ workspaceWithFactory.test( }, }, }; - await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('add_proposal', proposalUpgradeSelf, { + await root.call( + 'upgradedao.factory.test.near', + 'add_proposal', + proposalUpgradeSelf, + { attachedDeposit: toYocto('1'), gas: tGas(300), - }) - .signAndSend(); + }, + ); - result = await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('get_proposal', { id: 1 }, { gas: tGas(300) }) - .signAndSend(); - let new_proposal_1 = result.parseResult(); + let new_proposal_1: any = await root.call( + 'upgradedao.factory.test.near', + 'get_proposal', + { id: 1 }, + { gas: tGas(300) }, + ); test.log(new_proposal_1); test.is( @@ -166,20 +173,19 @@ workspaceWithFactory.test( test.is(new_proposal_1.status, 'InProgress'); test.truthy(new_proposal_1.kind.UpgradeSelf); - await root - .createTransaction('upgradedao.factory.test.near') - .functionCall( - 'act_proposal', - { id: 1, action: 'VoteApprove' }, - { gas: tGas(300) }, - ) - .signAndSend(); + await root.call( + 'upgradedao.factory.test.near', + 'act_proposal', + { id: 1, action: 'VoteApprove' }, + { gas: tGas(300) }, + ); - result = await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('get_proposal', { id: 1 }, { gas: tGas(300) }) - .signAndSend(); - let passed_proposal_1 = result.parseResult(); + let passed_proposal_1: any = await root.call( + 'upgradedao.factory.test.near', + 'get_proposal', + { id: 1 }, + { gas: tGas(300) }, + ); test.log(passed_proposal_1); test.is(passed_proposal_1.status, 'Approved'); @@ -213,19 +219,22 @@ workspaceWithFactory.test( // JSON.stringify(proposalRemoveContractBlob) // ); - await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('add_proposal', proposalRemoveContractBlob, { + await root.call( + 'upgradedao.factory.test.near', + 'add_proposal', + proposalRemoveContractBlob, + { attachedDeposit: toYocto('1'), gas: tGas(300), - }) - .signAndSend(); + }, + ); - result = await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('get_proposal', { id: 2 }, { gas: tGas(300) }) - .signAndSend(); - let new_proposal_2 = result.parseResult(); + let new_proposal_2: any = await root.call( + 'upgradedao.factory.test.near', + 'get_proposal', + { id: 2 }, + { gas: tGas(300) }, + ); test.log(new_proposal_2); test.is( @@ -240,20 +249,19 @@ workspaceWithFactory.test( `${factory.accountId}`, ); - await root - .createTransaction('upgradedao.factory.test.near') - .functionCall( - 'act_proposal', - { id: 2, action: 'VoteApprove' }, - { gas: tGas(300) }, - ) - .signAndSend(); + await root.call( + 'upgradedao.factory.test.near', + 'act_proposal', + { id: 2, action: 'VoteApprove' }, + { gas: tGas(300) }, + ); - result = await root - .createTransaction('upgradedao.factory.test.near') - .functionCall('get_proposal', { id: 2 }, { gas: tGas(300) }) - .signAndSend(); - let passed_proposal_2 = result.parseResult(); + let passed_proposal_2: any = await root.call( + 'upgradedao.factory.test.near', + 'get_proposal', + { id: 2 }, + { gas: tGas(300) }, + ); test.log(passed_proposal_2); test.is(passed_proposal_2.status, 'Approved'); From 6db5e79c22f7341e259f89483317decb9295d8be Mon Sep 17 00:00:00 2001 From: Constantin Dogaru Date: Fri, 25 Mar 2022 12:51:12 +0200 Subject: [PATCH 5/5] fix the bounty test --- sputnikdao2/tests-ava/__tests__/bounties.ava.ts | 3 ++- sputnikdao2/tests-ava/__tests__/utils.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sputnikdao2/tests-ava/__tests__/bounties.ava.ts b/sputnikdao2/tests-ava/__tests__/bounties.ava.ts index 2bf47f977..6cc5cca89 100644 --- a/sputnikdao2/tests-ava/__tests__/bounties.ava.ts +++ b/sputnikdao2/tests-ava/__tests__/bounties.ava.ts @@ -23,6 +23,7 @@ import { claimBounty, doneBounty, giveupBounty, + giveupBountyRaw, voteApprove, } from './utils'; @@ -243,7 +244,7 @@ workspace.test('Bounty giveup', async (test, { alice, root, dao }) => { //If within forgiveness period, `bounty_bond` should be returned ??? const balance1: NEAR = (await alice.balance()).total; - const result = await giveupBounty(alice, dao, proposalId); + const result = await giveupBountyRaw(alice, dao, proposalId); const balance2: NEAR = (await alice.balance()).total; test.is( Number(balance2.add(result.gas_burnt).toHuman().slice(0, -1)).toFixed( diff --git a/sputnikdao2/tests-ava/__tests__/utils.ts b/sputnikdao2/tests-ava/__tests__/utils.ts index f69fe2639..9b94da5d7 100644 --- a/sputnikdao2/tests-ava/__tests__/utils.ts +++ b/sputnikdao2/tests-ava/__tests__/utils.ts @@ -252,6 +252,14 @@ export async function giveupBounty( alice: NearAccount, dao: NearAccount, proposalId: number, +) { + return await alice.call(dao, 'bounty_giveup', { id: proposalId }); +} + +export async function giveupBountyRaw( + alice: NearAccount, + dao: NearAccount, + proposalId: number, ) { return await alice.call_raw(dao, 'bounty_giveup', { id: proposalId }); }