mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
always use Strings in Datatoken class
This commit is contained in:
parent
46ab602f28
commit
a3824f91c6
@ -67,14 +67,14 @@ export class DataTokens {
|
||||
* Approve
|
||||
* @param {String} dataTokenAddress
|
||||
* @param {String} toAddress
|
||||
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {string} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} address
|
||||
* @return {Promise<string>} transactionId
|
||||
*/
|
||||
public async approve(
|
||||
dataTokenAddress: string,
|
||||
spender: string,
|
||||
amount: number,
|
||||
amount: string,
|
||||
address: string
|
||||
): Promise<string> {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
@ -83,7 +83,7 @@ export class DataTokens {
|
||||
{ from: address }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods
|
||||
.approve(spender, this.web3.utils.toWei(String(amount)))
|
||||
.approve(spender, this.web3.utils.toWei(amount))
|
||||
.send()
|
||||
return trxReceipt
|
||||
}
|
||||
@ -92,14 +92,14 @@ export class DataTokens {
|
||||
* Mint
|
||||
* @param {String} dataTokenAddress
|
||||
* @param {String} address
|
||||
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} toAddress - only if toAddress is different from the minter
|
||||
* @return {Promise<string>} transactionId
|
||||
*/
|
||||
public async mint(
|
||||
dataTokenAddress: string,
|
||||
address: string,
|
||||
amount: number,
|
||||
amount: string,
|
||||
toAddress?: string
|
||||
): Promise<string> {
|
||||
const destAddress = toAddress || address
|
||||
@ -109,14 +109,14 @@ export class DataTokens {
|
||||
{ from: address }
|
||||
)
|
||||
const estGas = await datatoken.methods
|
||||
.mint(destAddress, this.web3.utils.toWei(String(amount)))
|
||||
.mint(destAddress, this.web3.utils.toWei(amount))
|
||||
.estimateGas(function (err, estGas) {
|
||||
if (err) console.log('Datatokens: ' + err)
|
||||
return estGas
|
||||
})
|
||||
|
||||
const trxReceipt = await datatoken.methods
|
||||
.mint(destAddress, this.web3.utils.toWei(String(amount)))
|
||||
.mint(destAddress, this.web3.utils.toWei(amount))
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
@ -130,14 +130,14 @@ export class DataTokens {
|
||||
* Transfer as number from address to toAddress
|
||||
* @param {String} dataTokenAddress
|
||||
* @param {String} toAddress
|
||||
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} address
|
||||
* @return {Promise<string>} transactionId
|
||||
*/
|
||||
public async transfer(
|
||||
dataTokenAddress: string,
|
||||
toAddress: string,
|
||||
amount: number,
|
||||
amount: string,
|
||||
address: string
|
||||
): Promise<string> {
|
||||
return this.transferToken(dataTokenAddress, toAddress, amount, address)
|
||||
@ -147,17 +147,17 @@ export class DataTokens {
|
||||
* Transfer as number from address to toAddress
|
||||
* @param {String} dataTokenAddress
|
||||
* @param {String} toAddress
|
||||
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} address
|
||||
* @return {Promise<string>} transactionId
|
||||
*/
|
||||
public async transferToken(
|
||||
dataTokenAddress: string,
|
||||
toAddress: string,
|
||||
amount: number,
|
||||
amount: string,
|
||||
address: string
|
||||
): Promise<string> {
|
||||
const weiAmount = this.web3.utils.toWei(String(amount))
|
||||
const weiAmount = this.web3.utils.toWei(amount)
|
||||
return this.transferWei(dataTokenAddress, toAddress, weiAmount, address)
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ export class DataTokens {
|
||||
* Transfer in wei from address to toAddress
|
||||
* @param {String} dataTokenAddress
|
||||
* @param {String} toAddress
|
||||
* @param {Number} amount Number of datatokens, as number. Expressed as wei
|
||||
* @param {String} amount Number of datatokens, as number. Expressed as wei
|
||||
* @param {String} address
|
||||
* @return {Promise<string>} transactionId
|
||||
*/
|
||||
@ -180,9 +180,7 @@ export class DataTokens {
|
||||
dataTokenAddress,
|
||||
{ from: address }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods
|
||||
.transfer(toAddress, String(amount))
|
||||
.send()
|
||||
const trxReceipt = await datatoken.methods.transfer(toAddress, amount).send()
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
@ -190,14 +188,14 @@ export class DataTokens {
|
||||
* Transfer from fromAddress to address (needs an Approve operation before)
|
||||
* @param {String} dataTokenAddress
|
||||
* @param {String} fromAddress
|
||||
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} amount Number of datatokens, as number. Will be converted to wei
|
||||
* @param {String} address
|
||||
* @return {Promise<string>} transactionId
|
||||
*/
|
||||
public async transferFrom(
|
||||
dataTokenAddress: string,
|
||||
fromAddress: string,
|
||||
amount: number,
|
||||
amount: string,
|
||||
address: string
|
||||
): Promise<string> {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
@ -206,7 +204,7 @@ export class DataTokens {
|
||||
{ from: address }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods
|
||||
.transferFrom(fromAddress, address, this.web3.utils.toWei(String(amount)))
|
||||
.transferFrom(fromAddress, address, this.web3.utils.toWei(amount))
|
||||
.send()
|
||||
return trxReceipt
|
||||
}
|
||||
@ -215,9 +213,9 @@ export class DataTokens {
|
||||
* Get Address Balance for datatoken
|
||||
* @param {String} dataTokenAddress
|
||||
* @param {String} address
|
||||
* @return {Promise<number>} balance Number of datatokens, as number. Will be converted from wei
|
||||
* @return {Promise<String>} balance Number of datatokens. Will be converted from wei
|
||||
*/
|
||||
public async balance(dataTokenAddress: string, address: string): Promise<number> {
|
||||
public async balance(dataTokenAddress: string, address: string): Promise<string> {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
@ -307,19 +305,19 @@ export class DataTokens {
|
||||
return this.web3.utils.fromWei(trxReceipt)
|
||||
}
|
||||
|
||||
/** Convert from number to wei
|
||||
* @param {Number} amount
|
||||
* @return {Promise<string>} string
|
||||
*/
|
||||
public toWei(amount) {
|
||||
return this.web3.utils.toWei(String(amount))
|
||||
}
|
||||
|
||||
/** Convert from wei to number
|
||||
/** Convert to wei
|
||||
* @param {String} amount
|
||||
* @return {Promise<string>} string
|
||||
*/
|
||||
public fromWei(amount) {
|
||||
public toWei(amount: string) {
|
||||
return this.web3.utils.toWei(amount)
|
||||
}
|
||||
|
||||
/** Convert from wei
|
||||
* @param {String} amount
|
||||
* @return {Promise<string>} string
|
||||
*/
|
||||
public fromWei(amount: string) {
|
||||
return this.web3.utils.fromWei(amount)
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ describe('Compute flow', () => {
|
||||
|
||||
const dateCreated = new Date(Date.now()).toISOString().split('.')[0] + 'Z' // remove milliseconds
|
||||
|
||||
const marketplaceAllowance = 20
|
||||
const tokenAmount = 100
|
||||
const marketplaceAllowance = '20'
|
||||
const tokenAmount = '100'
|
||||
|
||||
const timeout = 86400
|
||||
const algorithmMeta = {
|
||||
@ -114,7 +114,7 @@ describe('Compute flow', () => {
|
||||
})
|
||||
|
||||
it('Alice publishes dataset with a compute service that allows Raw Algo', async () => {
|
||||
price = datatoken.toWei(2) // in datatoken
|
||||
price = datatoken.toWei('2') // in datatoken
|
||||
cluster = ocean.compute.createClusterAttributes(
|
||||
'Kubernetes',
|
||||
'http://10.0.0.17/xxx'
|
||||
@ -261,7 +261,7 @@ describe('Compute flow', () => {
|
||||
})
|
||||
|
||||
it('Bob gets datatokens from Alice to be able to try the compute service', async () => {
|
||||
const dTamount = 20
|
||||
const dTamount = '20'
|
||||
await datatoken
|
||||
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
||||
.then(async () => {
|
||||
@ -284,7 +284,7 @@ describe('Compute flow', () => {
|
||||
const tx = await datatoken.transferWei(
|
||||
computeOrder['dataToken'],
|
||||
computeOrder['to'],
|
||||
computeOrder['numTokens'],
|
||||
String(computeOrder['numTokens']),
|
||||
computeOrder['from']
|
||||
)
|
||||
const response = await ocean.compute.start(
|
||||
@ -352,7 +352,7 @@ describe('Compute flow', () => {
|
||||
const algoTx = await datatoken.transferWei(
|
||||
algoOrder['dataToken'],
|
||||
algoOrder['to'],
|
||||
algoOrder['numTokens'],
|
||||
String(algoOrder['numTokens']),
|
||||
algoOrder['from']
|
||||
)
|
||||
const order = await ocean.compute.order(
|
||||
@ -367,7 +367,7 @@ describe('Compute flow', () => {
|
||||
const tx = await datatoken.transferWei(
|
||||
computeOrder['dataToken'],
|
||||
computeOrder['to'],
|
||||
computeOrder['numTokens'],
|
||||
String(computeOrder['numTokens']),
|
||||
computeOrder['from']
|
||||
)
|
||||
const response = await ocean.compute.start(
|
||||
|
@ -26,8 +26,8 @@ describe('Marketplace flow', () => {
|
||||
let data
|
||||
let blob
|
||||
|
||||
const marketplaceAllowance = 20
|
||||
const tokenAmount = 100
|
||||
const marketplaceAllowance = '20'
|
||||
const tokenAmount = '100'
|
||||
|
||||
describe('#MarketplaceDownloadFlow-Test', () => {
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
@ -84,7 +84,7 @@ describe('Marketplace flow', () => {
|
||||
})
|
||||
|
||||
it('Alice publishes a dataset', async () => {
|
||||
price = datatoken.toWei(10) // in datatoken
|
||||
price = datatoken.toWei('10') // in datatoken
|
||||
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
|
||||
const timeout = 0
|
||||
service1 = await ocean.assets.createAccessServiceAttributes(
|
||||
@ -146,11 +146,11 @@ describe('Marketplace flow', () => {
|
||||
it('Marketplace posts asset for sale', async () => {
|
||||
accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
|
||||
price = 20
|
||||
assert(accessService.attributes.main.cost * price === datatoken.toWei(200))
|
||||
assert(accessService.attributes.main.cost * price === datatoken.toWei('200'))
|
||||
})
|
||||
|
||||
it('Bob gets datatokens', async () => {
|
||||
const dTamount = 20
|
||||
const dTamount = '20'
|
||||
await datatoken
|
||||
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
||||
.then(async () => {
|
||||
@ -167,7 +167,7 @@ describe('Marketplace flow', () => {
|
||||
return await datatoken.transferWei(
|
||||
res['dataToken'],
|
||||
res['to'],
|
||||
res['numTokens'],
|
||||
String(res['numTokens']),
|
||||
res['from']
|
||||
)
|
||||
})
|
||||
|
@ -16,8 +16,8 @@ describe('Simple flow', () => {
|
||||
let datatoken
|
||||
let tokenAddress
|
||||
let transactionId
|
||||
const tokenAmount = 100
|
||||
const transferAmount = 1
|
||||
const tokenAmount = '100'
|
||||
const transferAmount = '1'
|
||||
const blob = 'http://localhost:8030/api/v1/services/consume'
|
||||
describe('#test', () => {
|
||||
it('Initialize Ocean contracts v3', async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user