mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #161 from oceanprotocol/feature/Fix_Incorrect-datatype-for-amount-in-datatoken.transferFrom
always use Strings in Datatoken class
This commit is contained in:
commit
285bb38943
@ -62,14 +62,14 @@ export class DataTokens {
|
|||||||
* Approve
|
* Approve
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} toAddress
|
* @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
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
public async approve(
|
public async approve(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
spender: string,
|
spender: string,
|
||||||
amount: number,
|
amount: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const datatoken = new this.web3.eth.Contract(
|
const datatoken = new this.web3.eth.Contract(
|
||||||
@ -78,7 +78,7 @@ export class DataTokens {
|
|||||||
{ from: address }
|
{ from: address }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods
|
const trxReceipt = await datatoken.methods
|
||||||
.approve(spender, this.web3.utils.toWei(String(amount)))
|
.approve(spender, this.web3.utils.toWei(amount))
|
||||||
.send()
|
.send()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
@ -87,14 +87,14 @@ export class DataTokens {
|
|||||||
* Mint
|
* Mint
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} address
|
* @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
|
* @param {String} toAddress - only if toAddress is different from the minter
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
public async mint(
|
public async mint(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
amount: number,
|
amount: string,
|
||||||
toAddress?: string
|
toAddress?: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const destAddress = toAddress || address
|
const destAddress = toAddress || address
|
||||||
@ -104,14 +104,14 @@ export class DataTokens {
|
|||||||
{ from: address }
|
{ from: address }
|
||||||
)
|
)
|
||||||
const estGas = await datatoken.methods
|
const estGas = await datatoken.methods
|
||||||
.mint(destAddress, this.web3.utils.toWei(String(amount)))
|
.mint(destAddress, this.web3.utils.toWei(amount))
|
||||||
.estimateGas(function (err, estGas) {
|
.estimateGas(function (err, estGas) {
|
||||||
if (err) console.log('Datatokens: ' + err)
|
if (err) console.log('Datatokens: ' + err)
|
||||||
return estGas
|
return estGas
|
||||||
})
|
})
|
||||||
|
|
||||||
const trxReceipt = await datatoken.methods
|
const trxReceipt = await datatoken.methods
|
||||||
.mint(destAddress, this.web3.utils.toWei(String(amount)))
|
.mint(destAddress, this.web3.utils.toWei(amount))
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -125,14 +125,14 @@ export class DataTokens {
|
|||||||
* Transfer as number from address to toAddress
|
* Transfer as number from address to toAddress
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} toAddress
|
* @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
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
public async transfer(
|
public async transfer(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
toAddress: string,
|
toAddress: string,
|
||||||
amount: number,
|
amount: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return this.transferToken(dataTokenAddress, toAddress, amount, address)
|
return this.transferToken(dataTokenAddress, toAddress, amount, address)
|
||||||
@ -142,17 +142,17 @@ export class DataTokens {
|
|||||||
* Transfer as number from address to toAddress
|
* Transfer as number from address to toAddress
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} toAddress
|
* @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
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
public async transferToken(
|
public async transferToken(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
toAddress: string,
|
toAddress: string,
|
||||||
amount: number,
|
amount: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<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)
|
return this.transferWei(dataTokenAddress, toAddress, weiAmount, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ export class DataTokens {
|
|||||||
* Transfer in wei from address to toAddress
|
* Transfer in wei from address to toAddress
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} toAddress
|
* @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
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
@ -175,9 +175,7 @@ export class DataTokens {
|
|||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
{ from: address }
|
{ from: address }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods
|
const trxReceipt = await datatoken.methods.transfer(toAddress, amount).send()
|
||||||
.transfer(toAddress, String(amount))
|
|
||||||
.send()
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,14 +183,14 @@ export class DataTokens {
|
|||||||
* Transfer from fromAddress to address (needs an Approve operation before)
|
* Transfer from fromAddress to address (needs an Approve operation before)
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} fromAddress
|
* @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
|
* @param {String} address
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
public async transferFrom(
|
public async transferFrom(
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
fromAddress: string,
|
fromAddress: string,
|
||||||
amount: number,
|
amount: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const datatoken = new this.web3.eth.Contract(
|
const datatoken = new this.web3.eth.Contract(
|
||||||
@ -201,7 +199,7 @@ export class DataTokens {
|
|||||||
{ from: address }
|
{ from: address }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods
|
const trxReceipt = await datatoken.methods
|
||||||
.transferFrom(fromAddress, address, this.web3.utils.toWei(String(amount)))
|
.transferFrom(fromAddress, address, this.web3.utils.toWei(amount))
|
||||||
.send()
|
.send()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
@ -210,9 +208,9 @@ export class DataTokens {
|
|||||||
* Get Address Balance for datatoken
|
* Get Address Balance for datatoken
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} address
|
* @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(
|
const datatoken = new this.web3.eth.Contract(
|
||||||
this.datatokensABI,
|
this.datatokensABI,
|
||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
@ -302,19 +300,19 @@ export class DataTokens {
|
|||||||
return this.web3.utils.fromWei(trxReceipt)
|
return this.web3.utils.fromWei(trxReceipt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert from number to wei
|
/** Convert to wei
|
||||||
* @param {Number} amount
|
|
||||||
* @return {Promise<string>} string
|
|
||||||
*/
|
|
||||||
public toWei(amount) {
|
|
||||||
return this.web3.utils.toWei(String(amount))
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Convert from wei to number
|
|
||||||
* @param {String} amount
|
* @param {String} amount
|
||||||
* @return {Promise<string>} string
|
* @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)
|
return this.web3.utils.fromWei(amount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ describe('Compute flow', () => {
|
|||||||
|
|
||||||
const dateCreated = new Date(Date.now()).toISOString().split('.')[0] + 'Z' // remove milliseconds
|
const dateCreated = new Date(Date.now()).toISOString().split('.')[0] + 'Z' // remove milliseconds
|
||||||
|
|
||||||
const tokenAmount = 100
|
const marketplaceAllowance = '20'
|
||||||
|
const tokenAmount = '100'
|
||||||
|
|
||||||
const timeout = 86400
|
const timeout = 86400
|
||||||
const algorithmMeta = {
|
const algorithmMeta = {
|
||||||
@ -105,7 +106,7 @@ describe('Compute flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('Alice publishes dataset with a compute service that allows Raw Algo', async () => {
|
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(
|
cluster = ocean.compute.createClusterAttributes(
|
||||||
'Kubernetes',
|
'Kubernetes',
|
||||||
'http://10.0.0.17/xxx'
|
'http://10.0.0.17/xxx'
|
||||||
@ -252,7 +253,7 @@ describe('Compute flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('Bob gets datatokens from Alice to be able to try the compute service', async () => {
|
it('Bob gets datatokens from Alice to be able to try the compute service', async () => {
|
||||||
const dTamount = 20
|
const dTamount = '20'
|
||||||
await datatoken
|
await datatoken
|
||||||
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
@ -275,7 +276,7 @@ describe('Compute flow', () => {
|
|||||||
const tx = await datatoken.transferWei(
|
const tx = await datatoken.transferWei(
|
||||||
computeOrder['dataToken'],
|
computeOrder['dataToken'],
|
||||||
computeOrder['to'],
|
computeOrder['to'],
|
||||||
computeOrder['numTokens'],
|
String(computeOrder['numTokens']),
|
||||||
computeOrder['from']
|
computeOrder['from']
|
||||||
)
|
)
|
||||||
const response = await ocean.compute.start(
|
const response = await ocean.compute.start(
|
||||||
@ -343,7 +344,7 @@ describe('Compute flow', () => {
|
|||||||
const algoTx = await datatoken.transferWei(
|
const algoTx = await datatoken.transferWei(
|
||||||
algoOrder['dataToken'],
|
algoOrder['dataToken'],
|
||||||
algoOrder['to'],
|
algoOrder['to'],
|
||||||
algoOrder['numTokens'],
|
String(algoOrder['numTokens']),
|
||||||
algoOrder['from']
|
algoOrder['from']
|
||||||
)
|
)
|
||||||
const order = await ocean.compute.order(
|
const order = await ocean.compute.order(
|
||||||
@ -358,7 +359,7 @@ describe('Compute flow', () => {
|
|||||||
const tx = await datatoken.transferWei(
|
const tx = await datatoken.transferWei(
|
||||||
computeOrder['dataToken'],
|
computeOrder['dataToken'],
|
||||||
computeOrder['to'],
|
computeOrder['to'],
|
||||||
computeOrder['numTokens'],
|
String(computeOrder['numTokens']),
|
||||||
computeOrder['from']
|
computeOrder['from']
|
||||||
)
|
)
|
||||||
const response = await ocean.compute.start(
|
const response = await ocean.compute.start(
|
||||||
|
@ -26,8 +26,8 @@ describe('Marketplace flow', () => {
|
|||||||
let data
|
let data
|
||||||
let blob
|
let blob
|
||||||
|
|
||||||
const marketplaceAllowance = 20
|
const marketplaceAllowance = '20'
|
||||||
const tokenAmount = 100
|
const tokenAmount = '100'
|
||||||
|
|
||||||
describe('#MarketplaceDownloadFlow-Test', () => {
|
describe('#MarketplaceDownloadFlow-Test', () => {
|
||||||
it('Initialize Ocean contracts v3', async () => {
|
it('Initialize Ocean contracts v3', async () => {
|
||||||
@ -84,7 +84,7 @@ describe('Marketplace flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('Alice publishes a dataset', async () => {
|
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 publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
|
||||||
const timeout = 0
|
const timeout = 0
|
||||||
service1 = await ocean.assets.createAccessServiceAttributes(
|
service1 = await ocean.assets.createAccessServiceAttributes(
|
||||||
@ -146,11 +146,11 @@ describe('Marketplace flow', () => {
|
|||||||
it('Marketplace posts asset for sale', async () => {
|
it('Marketplace posts asset for sale', async () => {
|
||||||
accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
|
accessService = await ocean.assets.getServiceByType(ddo.id, 'access')
|
||||||
price = 20
|
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 () => {
|
it('Bob gets datatokens', async () => {
|
||||||
const dTamount = 20
|
const dTamount = '20'
|
||||||
await datatoken
|
await datatoken
|
||||||
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
.transfer(tokenAddress, bob.getId(), dTamount, alice.getId())
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
@ -167,7 +167,7 @@ describe('Marketplace flow', () => {
|
|||||||
return await datatoken.transferWei(
|
return await datatoken.transferWei(
|
||||||
res['dataToken'],
|
res['dataToken'],
|
||||||
res['to'],
|
res['to'],
|
||||||
res['numTokens'],
|
String(res['numTokens']),
|
||||||
res['from']
|
res['from']
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -16,8 +16,8 @@ describe('Simple flow', () => {
|
|||||||
let datatoken
|
let datatoken
|
||||||
let tokenAddress
|
let tokenAddress
|
||||||
let transactionId
|
let transactionId
|
||||||
const tokenAmount = 100
|
const tokenAmount = '100'
|
||||||
const transferAmount = 1
|
const transferAmount = '1'
|
||||||
const blob = 'http://localhost:8030/api/v1/services/consume'
|
const blob = 'http://localhost:8030/api/v1/services/consume'
|
||||||
describe('#test', () => {
|
describe('#test', () => {
|
||||||
it('Initialize Ocean contracts v3', async () => {
|
it('Initialize Ocean contracts v3', async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user