-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc sandbox supporting treasury factory (#194)
This PR adds the `treasury-factory.near` contract and the dependencies `social.near` and `near` contracts to the RPC sandbox which can be used for Playwright tests and for experimenting in the [playground](https://github.com/NEAR-DevHub/neardevhub-treasury-dashboard/blob/feat/sandbox-treasury-factory/sandboxrpc/README.md). The file [sandboxrpc/playground/treasuryfactory.js](https://github.com/NEAR-DevHub/neardevhub-treasury-dashboard/blob/feat/sandbox-treasury-factory/sandboxrpc/playground/treasuryfactory.js) shows how to use the treasury factory with the sandbox. You can run this file with nodejs and test various ways of interaction. Also there is a [Playwright test](https://github.com/NEAR-DevHub/neardevhub-treasury-dashboard/blob/feat/sandbox-treasury-factory/playwright-tests/tests/treasury-factory/treasury-factory.spec.js) that shows how to use it in Playwright and make the needed assertions that a treasury instance was successfully created. This can be used as a starting point for creating the full E2E test in #191 Broken test fixes: - "Should update existing member permissions" ( the locator for finding the delete button was not specific enough ). - "Should whitelist staking pool and create stake delegation request" ( also made the locator more specific ). resolves #193
- Loading branch information
1 parent
cb566be
commit 1de6de0
Showing
13 changed files
with
405 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
playwright-tests/tests/treasury-factory/treasury-factory.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { SandboxRPC } from '../../util/sandboxrpc'; | ||
import { getLocalWidgetSource } from '../../util/bos-workspace'; | ||
import nearApi from 'near-api-js'; | ||
|
||
test("should be able to create a treasury instance with sandbox", async () => { | ||
const sandbox = new SandboxRPC(); | ||
await sandbox.init(); | ||
|
||
const widget_reference_account_id = 'treasury-testing.near'; | ||
|
||
await sandbox.setupWidgetReferenceAccount(widget_reference_account_id); | ||
|
||
const instance_name = "test-factory-created-instance"; | ||
const create_dao_args = { | ||
"config": { | ||
"name": instance_name, | ||
"purpose": "creating dao treasury", | ||
"metadata": "", | ||
}, | ||
"policy": { | ||
"roles": [ | ||
{ | ||
"kind": { | ||
"Group": ["acc3.near", "acc2.near", "acc1.near"], | ||
}, | ||
"name": "Create Requests", | ||
"permissions": [ | ||
"call:AddProposal", | ||
"transfer:AddProposal", | ||
"config:Finalize", | ||
], | ||
"vote_policy": {}, | ||
}, | ||
{ | ||
"kind": { | ||
"Group": ["acc1.near"], | ||
}, | ||
"name": "Manage Members", | ||
"permissions": [ | ||
"config:*", | ||
"policy:*", | ||
"add_member_to_role:*", | ||
"remove_member_from_role:*", | ||
], | ||
"vote_policy": {}, | ||
}, | ||
{ | ||
"kind": { | ||
"Group": ["acc1.near", "acc2.near"], | ||
}, | ||
"name": "Vote", | ||
"permissions": ["*:VoteReject", "*:VoteApprove", "*:VoteRemove"], | ||
"vote_policy": {}, | ||
}, | ||
], | ||
"default_vote_policy": { | ||
"weight_kind": "RoleWeight", | ||
"quorum": "0", | ||
"threshold": [1, 2], | ||
}, | ||
"proposal_bond": "100000000000000000000000", | ||
"proposal_period": "604800000000000", | ||
"bounty_bond": "100000000000000000000000", | ||
"bounty_forgiveness_period": "604800000000000", | ||
}, | ||
}; | ||
|
||
const createInstanceResult = await sandbox.account.functionCall({ | ||
contractId: "treasury-factory.near", methodName: 'create_instance', args: { | ||
"sputnik_dao_factory_account_id": "sputnik-dao.near", | ||
"social_db_account_id": "social.near", | ||
"widget_reference_account_id": widget_reference_account_id, | ||
"name": instance_name, | ||
"create_dao_args": Buffer.from(JSON.stringify(create_dao_args)).toString('base64') | ||
}, | ||
gas: 300000000000000, | ||
attachedDeposit: nearApi.utils.format.parseNearAmount("12") | ||
}); | ||
|
||
expect( | ||
createInstanceResult.receipts_outcome.filter(receipt_outcome => receipt_outcome.outcome.status.Failure).length | ||
).toBe(0); | ||
|
||
const web4GetResult = await sandbox.account.viewFunction({ contractId: `${instance_name}.near`, methodName: 'web4_get', args: { request: { path: "/" } } }); | ||
expect(Buffer.from(web4GetResult.body, 'base64').toString().substring(0, "<!doctype html>".length)).toEqual("<!doctype html>"); | ||
|
||
const daoGetPolicyResult = await sandbox.account.viewFunction({contractId: `${instance_name}.sputnik-dao.near`, methodName: 'get_policy', args: {}}); | ||
expect(daoGetPolicyResult).toEqual(create_dao_args.policy); | ||
|
||
const referenceWidgetSources = await getLocalWidgetSource(widget_reference_account_id + "/widget/**"); | ||
|
||
const socialGetResult = await sandbox.account.viewFunction({contractId: 'social.near', methodName: 'get', args: { | ||
"keys": [`${instance_name}.near/widget/**`] | ||
}}); | ||
|
||
expect(JSON.stringify(socialGetResult)).toEqual(JSON.stringify(referenceWidgetSources).replaceAll(widget_reference_account_id, instance_name+".near")); | ||
|
||
await sandbox.quitSandbox(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export async function getLocalWidgetSource(path) { | ||
const json = await fetch("http://127.0.0.1:8080/api/proxy-rpc", { | ||
method: "POST", | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
method: "query", | ||
params: { | ||
request_type: "call_function", | ||
account_id: "social.near", | ||
method_name: "get", | ||
args_base64: Buffer.from(JSON.stringify({ keys: [path] })).toString( | ||
"base64" | ||
), | ||
finality: "optimistic", | ||
}, | ||
id: 123, | ||
jsonrpc: "2.0", | ||
}), | ||
}).then((r) => r.json()); | ||
return JSON.parse( | ||
new TextDecoder().decode(new Uint8Array(json.result.result)) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
sandboxrpc/sandboxrpcplayground.js → sandboxrpc/playground/staking.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.