diff --git a/index.ts b/index.ts index 25dda546d1aed9f4c3ac6b910f2eaae6fb7437de..1661b238c46357e888d19dd624c90a4a3fa3f50b 100644 --- a/index.ts +++ b/index.ts @@ -56,7 +56,7 @@ program.command('main') case 'ADMIN': questions[0].choices = ['Résoudre une proposition', 'Clôturer une proposition', 'Voir les propositions', 'Créer un token'] - if (await handleHasToken(tezos)) { questions[0].choices.push('Bruler des tokens') } + if (await handleHasToken(tezos)) { questions[0].choices.push('Brûler un token') } await inquirer.prompt(questions).then(async (answers: { choice: string }) => { await handleAdminChoice(answers.choice, tezos) @@ -67,7 +67,7 @@ program.command('main') // CLOTURER ET RESOUDRE LES PROPOSITIONS DONT IL EST LE CREATEUR questions[0].choices = ['Faire une proposition', 'Voter pour une proposition', 'Voir les propositions', 'Créer un token'] - if (await handleHasToken(tezos)) { questions[0].choices.push('Bruler des tokens') } + if (await handleHasToken(tezos)) { questions[0].choices.push('Brûler un token') } await inquirer.prompt(questions).then(async (answers: { choice: string }) => { await handleAdherentChoice(answers.choice, tezos) @@ -76,7 +76,7 @@ program.command('main') case 'CONNECTED': questions[0].choices = ['Rejoindre une association', 'Voir les associations', "Voir les détails d'une association", 'Créer un token'] - if (await handleHasToken(tezos)) { questions[0].choices.push('Bruler des tokens', 'Créer une association') } + if (await handleHasToken(tezos)) { questions[0].choices.push('Brûler un token', 'Créer une association') } await inquirer.prompt(questions).then(async (answers: { choice: string }) => { await handleConnectedChoice(answers.choice, tezos) diff --git a/src/features/token/burnToken.ts b/src/features/token/burnToken.ts index 98060c4a21d8e299c5880539a76ed42dc1493eb5..2529c691566f8c8dcd18eadd863928a271b9b594 100644 --- a/src/features/token/burnToken.ts +++ b/src/features/token/burnToken.ts @@ -3,13 +3,13 @@ import chalk from 'chalk' import { handleBurnToken } from '../../handlers/token/tokenHandlers.js' /** - * Burns tokens. + * Burns token. * @param {TezosToolkit} tezos - The instance of the Tezos toolkit. - * @returns {Promise<void>} A promise resolved once the tokens are burned. + * @returns {Promise<void>} A promise resolved once the token is burned. */ async function burnToken (tezos: TezosToolkit): Promise<void> { await handleBurnToken(tezos).then(() => { - console.log(chalk.bgGreenBright('\nVous avez bruler vos tokens !!')) + console.log(chalk.bgGreenBright('\nVous avez brûler un token !!')) }).catch((error) => { console.log(chalk.bgRed(`\n${error.message}`)) }) diff --git a/src/handlers/roleHandlers.ts b/src/handlers/roleHandlers.ts index abe0d493f7499bf6017882fe8b05922eb2c50728..b10e92049ca63f17f37ba9401f45af600b68e3c1 100644 --- a/src/handlers/roleHandlers.ts +++ b/src/handlers/roleHandlers.ts @@ -24,7 +24,7 @@ async function handleAdminChoice (choice: string, tezos: TezosToolkit): Promise< case 'Créer un token': await createToken(tezos) break - case 'Bruler des tokens': + case 'Brûler un token': await burnToken(tezos) break case 'Résoudre une proposition': @@ -68,7 +68,7 @@ async function handleAdherentChoice (choice: string, tezos: TezosToolkit): Promi case 'Voir mon portefeuille': await showBalance(tezos) break - case 'Bruler des tokens': + case 'Brûler un token': await burnToken(tezos) break default: @@ -103,7 +103,7 @@ async function handleConnectedChoice (choice: string, tezos: TezosToolkit): Prom case 'Créer une association': await createAssociation(tezos) break - case 'Bruler des tokens': + case 'Brûler un token': await burnToken(tezos) break default: diff --git a/src/handlers/token/tokenHandlers.ts b/src/handlers/token/tokenHandlers.ts index 2c6d1f69a43526e93fb31b100c4f9af93d46c361..710e399aa230852077249613b0d6a3cd5e9cc764 100644 --- a/src/handlers/token/tokenHandlers.ts +++ b/src/handlers/token/tokenHandlers.ts @@ -14,8 +14,8 @@ async function handleCreateToken (tezos: TezosToolkit): Promise<void> { const questions = [ { type: 'input', - name: 'nbTokenFungible', - message: 'Nombre de token fongible', + name: 'tokens', + message: 'Nombre de token', validate: function (input: string) { const done = this.async() const parsedInput = parseFloat(input.trim()) @@ -29,17 +29,17 @@ async function handleCreateToken (tezos: TezosToolkit): Promise<void> { } ] - let nbTokenFungible: number + let tokens: number - await inquirer.prompt(questions).then(async (answers: { nbTokenFungible: number }) => { - nbTokenFungible = answers.nbTokenFungible + await inquirer.prompt(questions).then(async (answers: { tokens: string }) => { + const nbToken = parseInt(answers.tokens) + tokens = nbToken }) try { - await createFAToken(nbTokenFungible, tezos) + await createFAToken(tokens, tezos) } catch (error) { - const errorMessage = error.lastError?.with?.string ? error.lastError.with.string : 'Unknown error occurred' - throw new Error(`${errorMessage}`) + throw new Error(`${error}`) } } @@ -49,32 +49,8 @@ async function handleCreateToken (tezos: TezosToolkit): Promise<void> { * @returns {Promise<void>} A promise resolved once the proposal creation process is complete. */ async function handleBurnToken (tezos: TezosToolkit): Promise<void> { - const questions = [ - { - type: 'input', - name: 'nbTokenToBurn', - message: 'Nombre de token à bruler', - validate: function (input: string) { - const done = this.async() - const parsedInput = parseFloat(input.trim()) - - if (isNaN(parsedInput) || !Number.isInteger(parsedInput)) { - done('Vous devez fournir un nombre entier') - } else { - done(null, true) - } - } - } - ] - - let nbTokenToBurn: number - - await inquirer.prompt(questions).then(async (answers: { nbTokenToBurn: number }) => { - nbTokenToBurn = answers.nbTokenToBurn - }) - try { - await burnToken(nbTokenToBurn, tezos) + await burnToken(tezos) } catch (error) { const errorMessage = error.lastError?.with?.string ? error.lastError.with.string : 'Unknown error occurred' throw new Error(`${errorMessage}`) diff --git a/src/services/association.service.ts b/src/services/association.service.ts index 8c74d270d0abff38cfa574ca69bfd49f7e4b99fe..d9d196ae6ac546fe546256460815194eac27635c 100644 --- a/src/services/association.service.ts +++ b/src/services/association.service.ts @@ -2,7 +2,7 @@ import { type Operation, type TezosToolkit } from '@taquito/taquito' import { type Association } from '../types/Association' // NEED UPDATE ADDRESS !! (SMART CONTRACT 1: Registre des associations) -const address = 'KT1ACcRhzuDzVKpwzjZTudcQchEijvj7b7cp' +const address = 'KT1QTwmF2eptKss2FWbT1rHP5wCERL16kihQ' async function createAssociation (association: Association, tezos: TezosToolkit): Promise<void> { const contract = await tezos.contract.at(address) diff --git a/src/services/token.service.ts b/src/services/token.service.ts index 4835dd19c91fb42e7094ec7fcbbab260542db1cf..19bfaa28286134049b15aa47ef4006546c721fc1 100644 --- a/src/services/token.service.ts +++ b/src/services/token.service.ts @@ -1,22 +1,19 @@ import { type Operation, type TezosToolkit } from '@taquito/taquito' -// NEED UPDATE ADDRESS !! -const address = 'KT1QZJzhSPQ89K4eC59tmQYCt44qph7wXoJu' +const address = 'KT1Jrg6G9ziKbpSvzPLhjM4pXWYJqxoZdhMZ' -// NEED UPDATE ENTRYPOINT !! -async function createFAToken (nbTokenFongible: number, tezos: TezosToolkit): Promise<void> { - // const contract = await tezos.contract.at(address) - // const op: Operation = await contract.methodsObject.createFAToken(nbTokenFongible).send() +async function createFAToken (nbTokens: number, tezos: TezosToolkit): Promise<void> { + const contract = await tezos.contract.at(address) + const op: Operation = await contract.methodsObject.createContract(nbTokens).send() - // await op.confirmation() + await op.confirmation() } -// NEED UPDATE ENTRYPOINT !! -async function burnToken (amount: number, tezos: TezosToolkit): Promise<void> { - // const contract = await tezos.contract.at(address) - // const op: Operation = await contract.methodsObject.burnToken(amount).send() +async function burnToken (tezos: TezosToolkit): Promise<void> { + const contract = await tezos.contract.at(address) + const op: Operation = await contract.methodsObject.burn().send() - // await op.confirmation() + await op.confirmation() } // NEED UPDATE ENTRYPOINT !! diff --git a/src/utils/getRole.ts b/src/utils/getRole.ts index ea17ad81e7f32debbfa4bf5f6f0d993651a92259..d6de12fa4f7caaafe08aa2486790b3cb0ece1098 100644 --- a/src/utils/getRole.ts +++ b/src/utils/getRole.ts @@ -8,5 +8,5 @@ export async function getRole (tezos: TezosToolkit): Promise<Role> { // if (isAdmin) return 'ADMIN' // TEMPORARY - return 'ADHERENT' + return 'CONNECTED' } diff --git a/test/handlers/roleHandlers.spec.ts b/test/handlers/roleHandlers.spec.ts index 755f601ab93910318f2ce7d5d456236f1e26f217..190dc699d50be570d2b94f9fab1ab9a98159be21 100644 --- a/test/handlers/roleHandlers.spec.ts +++ b/test/handlers/roleHandlers.spec.ts @@ -73,9 +73,9 @@ describe('roleHandlers', () => { }) }) - describe('when choice is "Bruler des tokens"', () => { + describe('when choice is "Brûler un token"', () => { it('should call burnToken', async () => { - await handleAdminChoice('Bruler des tokens', mockedTezosToolkit) + await handleAdminChoice('Brûler un token', mockedTezosToolkit) expect(burnToken).toBeCalled() }) @@ -149,9 +149,9 @@ describe('roleHandlers', () => { }) }) - describe('when choice is "Bruler des tokens"', () => { + describe('when choice is "Brûler un token"', () => { it('should call burnToken', async () => { - await handleAdminChoice('Bruler des tokens', mockedTezosToolkit) + await handleAdminChoice('Brûler un token', mockedTezosToolkit) expect(burnToken).toBeCalled() }) @@ -216,9 +216,9 @@ describe('roleHandlers', () => { }) }) - describe('when choice is "Bruler des tokens"', () => { + describe('when choice is "Brûler un token"', () => { it('should call burnToken', async () => { - await handleAdminChoice('Bruler des tokens', mockedTezosToolkit) + await handleAdminChoice('Brûler un token', mockedTezosToolkit) expect(burnToken).toBeCalled() }) diff --git a/test/handlers/token/tokenHandlers.spec.ts b/test/handlers/token/tokenHandlers.spec.ts index bffd0e3355e69e9eb87bd711221506d9361dafc1..21ee4084811a0c39101104e8f8254cfe81432480 100644 --- a/test/handlers/token/tokenHandlers.spec.ts +++ b/test/handlers/token/tokenHandlers.spec.ts @@ -40,26 +40,21 @@ describe('tokenHandlers', () => { describe('handleCreateToken', () => { describe('when createFAToken is called with success', () => { - it('should create a token with provided nbTokenFungible', async () => { - const nbTokenFungible = 5 + it('should create a token with provided tokens', async () => { + const tokens = 5 - promptSpy.mockResolvedValueOnce({ nbTokenFungible }) + promptSpy.mockResolvedValueOnce({ tokens }) await handleCreateToken(mockedTezosToolkit) - expect(createFATokenSpy).toBeCalledWith(nbTokenFungible, mockedTezosToolkit) + expect(createFATokenSpy).toBeCalledWith(tokens, mockedTezosToolkit) }) }) describe('when createFAToken is called with error', () => { it('should throw error with correct message', async () => { - const error = { - lastError: { - with: { - string: 'Custom Error' - } - } - } + const error = 'Custom Error' + createFATokenSpy.mockRejectedValueOnce(error) const nbTokenFungible = 5 @@ -72,14 +67,10 @@ describe('tokenHandlers', () => { describe('handleBurnToken', () => { describe('when burnToken is called with success', () => { - it('should create a token with provided nbTokenToBurn', async () => { - const nbTokenToBurn = 5 - - promptSpy.mockResolvedValueOnce({ nbTokenToBurn }) - + it('should burn a token', async () => { await handleBurnToken(mockedTezosToolkit) - expect(burnTokenSpy).toBeCalledWith(nbTokenToBurn, mockedTezosToolkit) + expect(burnTokenSpy).toBeCalledWith(mockedTezosToolkit) }) }) @@ -93,9 +84,6 @@ describe('tokenHandlers', () => { } } burnTokenSpy.mockRejectedValueOnce(error) - const nbTokenToBurn = 5 - - promptSpy.mockResolvedValueOnce({ nbTokenToBurn }) await expect(handleBurnToken(mockedTezosToolkit)).rejects.toThrow('Custom Error') })