Skip to content
Snippets Groups Projects
Commit 31e75dcc authored by Nawfel Senoussi's avatar Nawfel Senoussi
Browse files

add burn and create token

parent 0cdb4220
Branches
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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}`))
})
......
......@@ -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:
......
......@@ -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}`)
......
......@@ -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)
......
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 !!
......
......@@ -8,5 +8,5 @@ export async function getRole (tezos: TezosToolkit): Promise<Role> {
// if (isAdmin) return 'ADMIN'
// TEMPORARY
return 'ADHERENT'
return 'CONNECTED'
}
......@@ -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()
})
......
......@@ -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')
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment