Skip to content

Commit

Permalink
Add missing symbol and name helper on datatoken (#1667)
Browse files Browse the repository at this point in the history
* add two helpers method

* fix tests

* update comments
  • Loading branch information
bogdanfazakas committed Dec 19, 2022
1 parent d539e00 commit cbc3cd6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/contracts/Datatoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,26 @@ export class Datatoken extends SmartContract {
return decimals
}

/** It returns the token symbol
* @param {String} dtAddress Datatoken adress
* @return {Promise<number>}
*/
public async getSymbol(dtAddress: string): Promise<string> {
const dtContract = this.getContract(dtAddress)
const symbol = await dtContract.methods.symbol().call()
return symbol
}

/** It returns the name of the token
* @param {String} dtAddress Datatoken adress
* @return {Promise<number>}
*/
public async getName(dtAddress: string): Promise<string> {
const dtContract = this.getContract(dtAddress)
const name = await dtContract.methods.name().call()
return name
}

/** It returns the token decimals, how many supported decimal points
* @param {String} dtAddress Datatoken adress
* @return {Promise<number>}
Expand Down
10 changes: 10 additions & 0 deletions test/unit/Datatoken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,16 @@ describe('Datatoken', () => {
assert(decimals === '18')
})

it('#getSymbol - should return the symbbol of the datatoken', async () => {
const symbol = await datatoken.getSymbol(datatokenAddress)
assert(symbol === 'ERC20DT1Symbol')
})

it('#getName - should return the name of the datatoken', async () => {
const name = await datatoken.getName(datatokenAddress)
assert(name === 'ERC20B1')
})

it('#transfer - we can transfer the datatoken', async () => {
const balance1before = await datatoken.balance(datatokenAddress, user1)
const balance2before = await datatoken.balance(datatokenAddress, user2)
Expand Down

0 comments on commit cbc3cd6

Please sign in to comment.