From 9e41db6fec20b71adcc66c03a68403864fe0d03a Mon Sep 17 00:00:00 2001 From: Zishan Date: Thu, 14 Dec 2023 02:51:18 +0530 Subject: [PATCH] feat(final-ui-tests): UI tests --- src/pages/newGrantProposal.tsx | 4 +- src/pages/proposal.tsx | 101 ++++++++++++++++++++++++++++++--- src/pages/proposalCard.tsx | 18 +++++- src/pages/proposals.tsx | 8 ++- 4 files changed, 116 insertions(+), 15 deletions(-) diff --git a/src/pages/newGrantProposal.tsx b/src/pages/newGrantProposal.tsx index 7ff8e02..b2975f5 100644 --- a/src/pages/newGrantProposal.tsx +++ b/src/pages/newGrantProposal.tsx @@ -21,8 +21,8 @@ const initialContractBoilerplate = `;; This is a boilerplate contract for a gran (define-public (execute (sender principal)) (begin - (try! (contract-call? .milestone-extension set-milestone (as-contract tx-sender) {id: u1, start-height: block-height, end-height: (+ block-height u1440), amount: u100000000} )) - (try! (contract-call? .milestone-extension set-milestone (as-contract tx-sender) {id: u2, start-height: (+ block-height u2880), end-height: u4320, amount: u100000000} )) + (try! (contract-call? .milestone-extension set-milestone (as-contract tx-sender) {id: u1, start-height: block-height, end-height: (+ block-height u2), amount: u100000000} )) + (try! (contract-call? .milestone-extension set-milestone (as-contract tx-sender) {id: u2, start-height: (+ block-height u2), end-height: (+ block-height u4), amount: u100000000} )) (ok true) ) ) diff --git a/src/pages/proposal.tsx b/src/pages/proposal.tsx index 456de39..e85996e 100644 --- a/src/pages/proposal.tsx +++ b/src/pages/proposal.tsx @@ -1,12 +1,16 @@ import React, { useEffect } from 'react'; import LeftMenu from '../components/leftMenu'; -import { useParams } from 'react-router-dom'; +import { useLocation, useParams, useSearchParams } from 'react-router-dom'; import { contractPrincipalCV, callReadOnlyFunction, - cvToValue + cvToValue, + FungibleConditionCode, + boolCV, + makeContractSTXPostCondition, + uintCV } from '@stacks/transactions'; -import { useAccount, useAuth } from '@micro-stacks/react'; +import { useAccount, useAuth, useOpenContractCall } from '@micro-stacks/react'; import { truncateAddress } from '../lib/utils'; type individualValue = { @@ -25,12 +29,76 @@ type ProposalType = { 'votes-for': individualValue; }; const ProposalPage = () => { - const { slug } = useParams(); + const { search } = useLocation(); + const query = new URLSearchParams(search); + const paramAddress = query.get('address'); + const paramContractName = query.get('contractName'); const [vote, setVote] = React.useState(''); + const [voteFor, setVoteFor] = React.useState('FOR'); const { isSignedIn } = useAuth(); const { stxAddress } = useAccount(); const [proposalInfo, setProposalInfo] = React.useState(); + const { openContractCall } = useOpenContractCall(); + + const voteForProposal = async () => { + const voteStatus = voteFor === 'FOR' ? true : false; + const functionArgs = [ + uintCV(vote), + boolCV(voteStatus), + contractPrincipalCV(paramAddress!, paramContractName!) + ]; + await openContractCall({ + contractAddress: 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM', + contractName: 'proposal-voting', + functionName: 'vote', + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + functionArgs, + + onFinish: async (data: any) => { + console.log('finished contract call!', data); + }, + onCancel: () => { + console.log('popup closed!'); + } + }); + }; + + const concludeProposal = async () => { + const postConditions = [ + makeContractSTXPostCondition( + 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM', + 'milestone-exntension', + FungibleConditionCode.LessEqual, + 1000000000000n + ) + ]; + const functionArgs = [ + contractPrincipalCV(paramAddress!, paramContractName!) + ]; + await openContractCall({ + contractAddress: 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM', + contractName: 'proposal-voting', + functionName: 'conclude', + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + functionArgs, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + postConditions, + + onFinish: async (data: any) => { + console.log('finished contract call!', data); + }, + onCancel: () => { + console.log('popup closed!'); + } + }); + }; + const fetchProposalInfo = async (address: string, contractName: string) => { if (isSignedIn) { try { @@ -56,6 +124,7 @@ const ProposalPage = () => { address: string, contractName: string ) => { + console.log('fetching milestones', address, contractName); if (isSignedIn) { try { const functionArgs = [contractPrincipalCV(address, contractName)]; @@ -68,7 +137,7 @@ const ProposalPage = () => { senderAddress: stxAddress! }); - console.log(cvToValue(result).value); + console.log(cvToValue(result)); } catch (error) { console.error('Failed to fetch balance:', error); } @@ -76,8 +145,8 @@ const ProposalPage = () => { }; useEffect(() => { - fetchProposalInfo(stxAddress!, slug!); - fetchProposalMilestoneInfo(stxAddress!, slug!); + fetchProposalInfo(paramAddress!, paramContractName!); + fetchProposalMilestoneInfo(paramAddress!, paramContractName!); }, []); return ( @@ -88,7 +157,7 @@ const ProposalPage = () => {
-

{`Proposal ${slug}`}

+

{`Proposal ${paramContractName}`}


@@ -104,13 +173,29 @@ const ProposalPage = () => { placeholder="vote number" className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" /> +