mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
commit
bce7c6c9d2
255
package-lock.json
generated
255
package-lock.json
generated
@ -487,6 +487,17 @@
|
||||
"@ethersproject/logger": ">=5.0.0-beta.137"
|
||||
}
|
||||
},
|
||||
"@ethersproject/signing-key": {
|
||||
"version": "5.0.0-beta.136",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/signing-key/-/signing-key-5.0.0-beta.136.tgz",
|
||||
"integrity": "sha512-iFIpafhDoxziOsnQaq39Hzdedji3cnuJymBHuLbO/elKZBEFrAoxPNE5YroxXdug634gncy5xDYDzmsIZ9y7mg==",
|
||||
"requires": {
|
||||
"@ethersproject/bytes": ">=5.0.0-beta.137",
|
||||
"@ethersproject/logger": ">=5.0.0-beta.137",
|
||||
"@ethersproject/properties": ">=5.0.0-beta.140",
|
||||
"elliptic": "6.5.2"
|
||||
}
|
||||
},
|
||||
"@ethersproject/strings": {
|
||||
"version": "5.0.0-beta.137",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/strings/-/strings-5.0.0-beta.137.tgz",
|
||||
@ -497,6 +508,22 @@
|
||||
"@ethersproject/logger": ">=5.0.0-beta.137"
|
||||
}
|
||||
},
|
||||
"@ethersproject/transactions": {
|
||||
"version": "5.0.0-beta.136",
|
||||
"resolved": "https://registry.npmjs.org/@ethersproject/transactions/-/transactions-5.0.0-beta.136.tgz",
|
||||
"integrity": "sha512-IActPKqttlerqexp0+3bVHiFAfQ5/kjaQ+kSwjM8+vdOjvncBQWLF5NHorpu2ikQM6ub1daPwTWZn1JJeKvhkA==",
|
||||
"requires": {
|
||||
"@ethersproject/address": ">=5.0.0-beta.134",
|
||||
"@ethersproject/bignumber": ">=5.0.0-beta.138",
|
||||
"@ethersproject/bytes": ">=5.0.0-beta.137",
|
||||
"@ethersproject/constants": ">=5.0.0-beta.133",
|
||||
"@ethersproject/keccak256": ">=5.0.0-beta.131",
|
||||
"@ethersproject/logger": ">=5.0.0-beta.137",
|
||||
"@ethersproject/properties": ">=5.0.0-beta.140",
|
||||
"@ethersproject/rlp": ">=5.0.0-beta.132",
|
||||
"@ethersproject/signing-key": ">=5.0.0-beta.135"
|
||||
}
|
||||
},
|
||||
"@iarna/toml": {
|
||||
"version": "2.2.5",
|
||||
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
|
||||
@ -14312,6 +14339,24 @@
|
||||
"web3-eth-personal": "1.2.8",
|
||||
"web3-net": "1.2.8",
|
||||
"web3-utils": "1.2.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"web3-eth-contract": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/web3-eth-contract/-/web3-eth-contract-1.2.8.tgz",
|
||||
"integrity": "sha512-EWRLVhZksbzGAyHd7RaOsakjCJBA2BREWiJmBDlrxDBqw8HltXFzKdkRug/mwVNa5ZYMabKSRF/MMh0Sx06CFw==",
|
||||
"requires": {
|
||||
"@types/bn.js": "^4.11.4",
|
||||
"underscore": "1.9.1",
|
||||
"web3-core": "1.2.8",
|
||||
"web3-core-helpers": "1.2.8",
|
||||
"web3-core-method": "1.2.8",
|
||||
"web3-core-promievent": "1.2.8",
|
||||
"web3-core-subscriptions": "1.2.8",
|
||||
"web3-eth-abi": "1.2.8",
|
||||
"web3-utils": "1.2.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"web3-eth-abi": {
|
||||
@ -14360,19 +14405,191 @@
|
||||
}
|
||||
},
|
||||
"web3-eth-contract": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/web3-eth-contract/-/web3-eth-contract-1.2.8.tgz",
|
||||
"integrity": "sha512-EWRLVhZksbzGAyHd7RaOsakjCJBA2BREWiJmBDlrxDBqw8HltXFzKdkRug/mwVNa5ZYMabKSRF/MMh0Sx06CFw==",
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-eth-contract/-/web3-eth-contract-1.2.9.tgz",
|
||||
"integrity": "sha512-PYMvJf7EG/HyssUZa+pXrc8IB06K/YFfWYyW4R7ed3sab+9wWUys1TlWxBCBuiBXOokSAyM6H6P6/cKEx8FT8Q==",
|
||||
"requires": {
|
||||
"@types/bn.js": "^4.11.4",
|
||||
"underscore": "1.9.1",
|
||||
"web3-core": "1.2.8",
|
||||
"web3-core-helpers": "1.2.8",
|
||||
"web3-core-method": "1.2.8",
|
||||
"web3-core-promievent": "1.2.8",
|
||||
"web3-core-subscriptions": "1.2.8",
|
||||
"web3-eth-abi": "1.2.8",
|
||||
"web3-utils": "1.2.8"
|
||||
"web3-core": "1.2.9",
|
||||
"web3-core-helpers": "1.2.9",
|
||||
"web3-core-method": "1.2.9",
|
||||
"web3-core-promievent": "1.2.9",
|
||||
"web3-core-subscriptions": "1.2.9",
|
||||
"web3-eth-abi": "1.2.9",
|
||||
"web3-utils": "1.2.9"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "12.12.47",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.47.tgz",
|
||||
"integrity": "sha512-yzBInQFhdY8kaZmqoL2+3U5dSTMrKaYcb561VU+lDzAYvqt+2lojvBEy+hmpSNuXnPTx7m9+04CzWYOUqWME2A=="
|
||||
},
|
||||
"bn.js": {
|
||||
"version": "4.11.8",
|
||||
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
|
||||
"integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
|
||||
},
|
||||
"eth-lib": {
|
||||
"version": "0.2.7",
|
||||
"resolved": "https://registry.npmjs.org/eth-lib/-/eth-lib-0.2.7.tgz",
|
||||
"integrity": "sha1-L5Pxex4jrsN1nNSj/iDBKGo/wco=",
|
||||
"requires": {
|
||||
"bn.js": "^4.11.6",
|
||||
"elliptic": "^6.4.0",
|
||||
"xhr-request-promise": "^0.1.2"
|
||||
}
|
||||
},
|
||||
"web3-core": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-core/-/web3-core-1.2.9.tgz",
|
||||
"integrity": "sha512-fSYv21IP658Ty2wAuU9iqmW7V+75DOYMVZsDH/c14jcF/1VXnedOcxzxSj3vArsCvXZNe6XC5/wAuGZyQwR9RA==",
|
||||
"requires": {
|
||||
"@types/bn.js": "^4.11.4",
|
||||
"@types/node": "^12.6.1",
|
||||
"bignumber.js": "^9.0.0",
|
||||
"web3-core-helpers": "1.2.9",
|
||||
"web3-core-method": "1.2.9",
|
||||
"web3-core-requestmanager": "1.2.9",
|
||||
"web3-utils": "1.2.9"
|
||||
}
|
||||
},
|
||||
"web3-core-helpers": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-core-helpers/-/web3-core-helpers-1.2.9.tgz",
|
||||
"integrity": "sha512-t0WAG3orLCE3lqi77ZoSRNFok3VQWZXTniZigDQjyOJYMAX7BU3F3js8HKbjVnAxlX3tiKoDxI0KBk9F3AxYuw==",
|
||||
"requires": {
|
||||
"underscore": "1.9.1",
|
||||
"web3-eth-iban": "1.2.9",
|
||||
"web3-utils": "1.2.9"
|
||||
}
|
||||
},
|
||||
"web3-core-method": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-core-method/-/web3-core-method-1.2.9.tgz",
|
||||
"integrity": "sha512-bjsIoqP3gs7A/gP8+QeLUCyOKJ8bopteCSNbCX36Pxk6TYfYWNuC6hP+2GzUuqdP3xaZNe+XEElQFUNpR3oyAg==",
|
||||
"requires": {
|
||||
"@ethersproject/transactions": "^5.0.0-beta.135",
|
||||
"underscore": "1.9.1",
|
||||
"web3-core-helpers": "1.2.9",
|
||||
"web3-core-promievent": "1.2.9",
|
||||
"web3-core-subscriptions": "1.2.9",
|
||||
"web3-utils": "1.2.9"
|
||||
}
|
||||
},
|
||||
"web3-core-promievent": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-core-promievent/-/web3-core-promievent-1.2.9.tgz",
|
||||
"integrity": "sha512-0eAUA2zjgXTleSrnc1wdoKQPPIHU6KHf4fAscu4W9kKrR+mqP1KsjYrxY9wUyjNnXxfQ+5M29ipvbiaK8OqdOw==",
|
||||
"requires": {
|
||||
"eventemitter3": "3.1.2"
|
||||
}
|
||||
},
|
||||
"web3-core-requestmanager": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-core-requestmanager/-/web3-core-requestmanager-1.2.9.tgz",
|
||||
"integrity": "sha512-1PwKV2m46ALUnIN5VPPgjOj8yMLJhhqZYvYJE34hTN5SErOkwhzx5zScvo5MN7v7KyQGFnpVCZKKGCiEnDmtFA==",
|
||||
"requires": {
|
||||
"underscore": "1.9.1",
|
||||
"web3-core-helpers": "1.2.9",
|
||||
"web3-providers-http": "1.2.9",
|
||||
"web3-providers-ipc": "1.2.9",
|
||||
"web3-providers-ws": "1.2.9"
|
||||
}
|
||||
},
|
||||
"web3-core-subscriptions": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-core-subscriptions/-/web3-core-subscriptions-1.2.9.tgz",
|
||||
"integrity": "sha512-Y48TvXPSPxEM33OmXjGVDMzTd0j8X0t2+sDw66haeBS8eYnrEzasWuBZZXDq0zNUsqyxItgBGDn+cszkgEnFqg==",
|
||||
"requires": {
|
||||
"eventemitter3": "3.1.2",
|
||||
"underscore": "1.9.1",
|
||||
"web3-core-helpers": "1.2.9"
|
||||
}
|
||||
},
|
||||
"web3-eth-abi": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-eth-abi/-/web3-eth-abi-1.2.9.tgz",
|
||||
"integrity": "sha512-3YwUYbh/DMfDbhMWEebAdjSd5bj3ZQieOjLzWFHU23CaLEqT34sUix1lba+hgUH/EN6A7bKAuKOhR3p0OvTn7Q==",
|
||||
"requires": {
|
||||
"@ethersproject/abi": "5.0.0-beta.153",
|
||||
"underscore": "1.9.1",
|
||||
"web3-utils": "1.2.9"
|
||||
}
|
||||
},
|
||||
"web3-eth-iban": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-eth-iban/-/web3-eth-iban-1.2.9.tgz",
|
||||
"integrity": "sha512-RtdVvJE0pyg9dHLy0GzDiqgnLnssSzfz/JYguhC1wsj9+Gnq1M6Diy3NixACWUAp6ty/zafyOaZnNQ+JuH9TjQ==",
|
||||
"requires": {
|
||||
"bn.js": "4.11.8",
|
||||
"web3-utils": "1.2.9"
|
||||
}
|
||||
},
|
||||
"web3-providers-http": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-providers-http/-/web3-providers-http-1.2.9.tgz",
|
||||
"integrity": "sha512-F956tCIj60Ttr0UvEHWFIhx+be3He8msoPzyA44/kfzzYoMAsCFRn5cf0zQG6al0znE75g6HlWVSN6s3yAh51A==",
|
||||
"requires": {
|
||||
"web3-core-helpers": "1.2.9",
|
||||
"xhr2-cookies": "1.1.0"
|
||||
}
|
||||
},
|
||||
"web3-providers-ipc": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-providers-ipc/-/web3-providers-ipc-1.2.9.tgz",
|
||||
"integrity": "sha512-NQ8QnBleoHA2qTJlqoWu7EJAD/FR5uimf7Ielzk4Z2z+m+6UAuJdJMSuQNj+Umhz9L/Ys6vpS1vHx9NizFl+aQ==",
|
||||
"requires": {
|
||||
"oboe": "2.1.4",
|
||||
"underscore": "1.9.1",
|
||||
"web3-core-helpers": "1.2.9"
|
||||
}
|
||||
},
|
||||
"web3-providers-ws": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-providers-ws/-/web3-providers-ws-1.2.9.tgz",
|
||||
"integrity": "sha512-6+UpvINeI//dglZoAKStUXqxDOXJy6Iitv2z3dbgInG4zb8tkYl/VBDL80UjUg3ZvzWG0g7EKY2nRPEpON2TFA==",
|
||||
"requires": {
|
||||
"eventemitter3": "^4.0.0",
|
||||
"underscore": "1.9.1",
|
||||
"web3-core-helpers": "1.2.9",
|
||||
"websocket": "^1.0.31"
|
||||
},
|
||||
"dependencies": {
|
||||
"eventemitter3": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.4.tgz",
|
||||
"integrity": "sha512-rlaVLnVxtxvoyLsQQFBx53YmXHDxRIzzTLbdfxqi4yocpSjAxXwkU0cScM5JgSKMqEhrZpnvQ2D9gjylR0AimQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"web3-utils": {
|
||||
"version": "1.2.9",
|
||||
"resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.2.9.tgz",
|
||||
"integrity": "sha512-9hcpuis3n/LxFzEVjwnVgvJzTirS2S9/MiNAa7l4WOEoywY+BSNwnRX4MuHnjkh9NY25B6QOjuNG6FNnSjTw1w==",
|
||||
"requires": {
|
||||
"bn.js": "4.11.8",
|
||||
"eth-lib": "0.2.7",
|
||||
"ethereum-bloom-filters": "^1.0.6",
|
||||
"ethjs-unit": "0.1.6",
|
||||
"number-to-bn": "1.7.0",
|
||||
"randombytes": "^2.1.0",
|
||||
"underscore": "1.9.1",
|
||||
"utf8": "3.0.0"
|
||||
}
|
||||
},
|
||||
"websocket": {
|
||||
"version": "1.0.31",
|
||||
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.31.tgz",
|
||||
"integrity": "sha512-VAouplvGKPiKFDTeCCO65vYHsyay8DqoBSlzIO3fayrfOgU94lQN5a1uWVnFrMLceTJw/+fQXR5PGbUVRaHshQ==",
|
||||
"requires": {
|
||||
"debug": "^2.2.0",
|
||||
"es5-ext": "^0.10.50",
|
||||
"nan": "^2.14.0",
|
||||
"typedarray-to-buffer": "^3.1.5",
|
||||
"yaeti": "^0.0.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"web3-eth-ens": {
|
||||
@ -14389,6 +14606,24 @@
|
||||
"web3-eth-abi": "1.2.8",
|
||||
"web3-eth-contract": "1.2.8",
|
||||
"web3-utils": "1.2.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"web3-eth-contract": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/web3-eth-contract/-/web3-eth-contract-1.2.8.tgz",
|
||||
"integrity": "sha512-EWRLVhZksbzGAyHd7RaOsakjCJBA2BREWiJmBDlrxDBqw8HltXFzKdkRug/mwVNa5ZYMabKSRF/MMh0Sx06CFw==",
|
||||
"requires": {
|
||||
"@types/bn.js": "^4.11.4",
|
||||
"underscore": "1.9.1",
|
||||
"web3-core": "1.2.8",
|
||||
"web3-core-helpers": "1.2.8",
|
||||
"web3-core-method": "1.2.8",
|
||||
"web3-core-promievent": "1.2.8",
|
||||
"web3-core-subscriptions": "1.2.8",
|
||||
"web3-eth-abi": "1.2.8",
|
||||
"web3-utils": "1.2.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"web3-eth-iban": {
|
||||
|
@ -16,7 +16,8 @@
|
||||
"run": "ts-node",
|
||||
"release": "release-it --non-interactive",
|
||||
"changelog": "auto-changelog -p",
|
||||
"prepublishOnly": "npm run build"
|
||||
"prepublishOnly": "npm run build",
|
||||
"test": "mocha --opts test/unit/mocha.opts"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -41,6 +42,7 @@
|
||||
"save-file": "^2.3.1",
|
||||
"uuid": "^8.0.0",
|
||||
"web3": "^1.2.6",
|
||||
"web3-eth-contract": "^1.2.9",
|
||||
"whatwg-url": "^8.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -5,7 +5,7 @@ const defaultDatatokensABI = require('../datatokens/DatatokensABI.json')
|
||||
|
||||
/**
|
||||
* Provides a interface to DataTokens
|
||||
|
||||
|
||||
*/
|
||||
export class DataTokens {
|
||||
public factoryAddress: string
|
||||
@ -46,12 +46,22 @@ export class DataTokens {
|
||||
): Promise<string> {
|
||||
// Create factory contract object
|
||||
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
|
||||
from: account.getId()
|
||||
from: account
|
||||
})
|
||||
const estGas = await factory.methods
|
||||
.createToken(metaDataStoreURI)
|
||||
.estimateGas(function(err, estGas){
|
||||
return estGas
|
||||
})
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await factory.methods
|
||||
.createToken(metaDataStoreURI)
|
||||
.send()
|
||||
.createToken(metaDataStoreURI)
|
||||
.send({
|
||||
from: account,
|
||||
gas: estGas+1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
|
||||
let tokenAddress = null
|
||||
try {
|
||||
tokenAddress = trxReceipt.events.TokenCreated.returnValues[0]
|
||||
@ -78,32 +88,12 @@ export class DataTokens {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
{ from: account.getId() }
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods.approve(spender, amount).send()
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve & Lock for a specified number of blocks (reverts after that if not used)
|
||||
* @param {String} dataTokenAddress
|
||||
* @param {String} toAddress
|
||||
* @param {Number} amount
|
||||
* @param {Number} blocks
|
||||
* @param {Account} account
|
||||
* @return {Promise<string>} transactionId
|
||||
*/
|
||||
public async approveAndLock(
|
||||
dataTokenAddress: string,
|
||||
toAddress: string,
|
||||
amount: number,
|
||||
blocks: number,
|
||||
account: Account
|
||||
): Promise<string> {
|
||||
// TO DO
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Mint
|
||||
* @param {String} dataTokenAddress
|
||||
@ -118,13 +108,25 @@ export class DataTokens {
|
||||
amount: number,
|
||||
toAddress?: string
|
||||
): Promise<string> {
|
||||
const address = toAddress || account.getId()
|
||||
const address = toAddress || account
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
{ from: account.getId() }
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods.mint(address, amount).send()
|
||||
|
||||
const estGas = await datatoken.methods.mint(address, amount)
|
||||
.estimateGas(function(err, estGas){
|
||||
return estGas
|
||||
})
|
||||
|
||||
const trxReceipt = await datatoken.methods.mint(address, amount)
|
||||
.send({
|
||||
from:account,
|
||||
gas: estGas*2,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
@ -145,7 +147,7 @@ export class DataTokens {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
{ from: account.getId() }
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods.transfer(toAddress, amount).send()
|
||||
return trxReceipt
|
||||
@ -168,10 +170,10 @@ export class DataTokens {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
{ from: account.getId() }
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods
|
||||
.transferFrom(fromAddress, account.getId(), amount)
|
||||
.transferFrom(fromAddress, account, amount)
|
||||
.send()
|
||||
return trxReceipt
|
||||
}
|
||||
@ -186,9 +188,9 @@ export class DataTokens {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
{ from: account.getId() }
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods.balanceOf(account.getId()).call()
|
||||
const trxReceipt = await datatoken.methods.balanceOf(account).call()
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
@ -251,4 +253,4 @@ export class DataTokens {
|
||||
const trxReceipt = await datatoken.methods.cap().call()
|
||||
return trxReceipt
|
||||
}
|
||||
}
|
||||
}
|
@ -195,10 +195,6 @@
|
||||
{
|
||||
"name": "blob",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "feeManager",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
@ -271,10 +267,6 @@
|
||||
{
|
||||
"name": "blob",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "feeManager",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "initialize",
|
||||
|
@ -1,4 +1,27 @@
|
||||
[
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "str1",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "str2",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "concatenateStrings",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "pure",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
@ -23,10 +46,6 @@
|
||||
{
|
||||
"name": "_template",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_feeManager",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
|
66
test/unit/Datatokens.test.ts
Normal file
66
test/unit/Datatokens.test.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { assert } from 'chai'
|
||||
import { TestContractHandler } from './TestContractHandler'
|
||||
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||
|
||||
const Web3 = require('web3')
|
||||
const web3 = new Web3("http://127.0.0.1:8545")
|
||||
|
||||
const factoryABI = require('../../src/datatokens/FactoryABI.json')
|
||||
const datatokensABI = require('../../src/datatokens/DatatokensABI.json')
|
||||
|
||||
describe('DataTokens', () => {
|
||||
|
||||
let minter
|
||||
let spender
|
||||
let balance
|
||||
let contracts
|
||||
let datatoken
|
||||
let tokenAddress
|
||||
|
||||
let tokenAmount = 100
|
||||
let blob = 'https://example.com/dataset-1'
|
||||
|
||||
describe('#test', () => {
|
||||
it('should deploy contracts', async () => {
|
||||
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
||||
await contracts.getAccounts()
|
||||
minter = contracts.accounts[0]
|
||||
spender = contracts.accounts[1]
|
||||
await contracts.deployContracts(minter)
|
||||
})
|
||||
|
||||
it('should create Datatoken object', async () => {
|
||||
datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
||||
assert(datatoken !== null)
|
||||
})
|
||||
|
||||
it('should create Datatoken contract', async () => {
|
||||
tokenAddress = await datatoken.create(blob, minter)
|
||||
assert(tokenAddress !== null)
|
||||
})
|
||||
|
||||
it('should mint Datatokens', async () => {
|
||||
await datatoken.mint(tokenAddress, minter, tokenAmount)
|
||||
balance = await datatoken.balance(tokenAddress, minter)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
|
||||
it('should transfer Datatokens to spender', async () => {
|
||||
await datatoken.transfer(tokenAddress, spender, tokenAmount, minter)
|
||||
balance = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
|
||||
})
|
||||
|
||||
it('should approve Datatokens to spend', async () => {
|
||||
await datatoken.approve(tokenAddress, minter, tokenAmount, spender)
|
||||
})
|
||||
|
||||
it('should transferFrom Datatokens back to the minter', async () => {
|
||||
await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter)
|
||||
minter = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
|
||||
})
|
||||
})
|
77
test/unit/TestContractHandler.ts
Normal file
77
test/unit/TestContractHandler.ts
Normal file
File diff suppressed because one or more lines are too long
8
test/unit/mocha.opts
Normal file
8
test/unit/mocha.opts
Normal file
@ -0,0 +1,8 @@
|
||||
--require ts-node/register
|
||||
--require source-map-support/register
|
||||
--require mock-local-storage
|
||||
--full-trace
|
||||
--bail
|
||||
--exit
|
||||
--timeout 20000
|
||||
test/unit/config.ts test/unit/**/*.test.ts
|
Loading…
x
Reference in New Issue
Block a user