MyNearWallet
Web wallet for NEAR Protocol
Agora vamos testar a adição de candidatos em uma eleição
test("candidate can be added to election", async (t) => {
const { contract, root } = t.context.accounts
const now = new Date().getTime()
// Crea la elección
await root.call(contract, "create_election", {
endsAt: now + 1000 * 60 * 60,
name: "Test Election",
startsAt: now,
})
// Agrega el candidato
await root.call(contract, "add_candidate_to_election", {
accountId: "test.accountId",
electionId: 0
})
// Obtiene todos los candidatos de la elección
const election: Election = await contract.view("get_candidates_by_election", { electionId: 0 })
const candidate: Candidate = election.candidates[0]
t.deepEqual(candidate, {
accountId: 'test.accountId', totalVotes: 0
})
})
Como a gente reinicia o ambiente após cada teste, devemos criar uma nova eleição antes de adicionar um candidato. Lembre-se das nossas validações no contrato.
Após adicionar um candidato a essa eleição, usando o método *deepEqual* para verificar a equidade dos objetos.
Connect Your Wallet

What is a Wallet?
Safely store and transfer your crypto and NFTs.
No need to create new accounts or credentials. Connect your wallet and you are good to go!