polkamarkets-js 1.0.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.openzeppelin/unknown-1337.json +2056 -0
- package/CONTRIBUTING.md +36 -0
- package/README.md +24 -25
- package/_book/README.md +590 -0
- package/_book/core.md +50 -0
- package/_book/gitbook/fonts/fontawesome/FontAwesome.otf +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.svg +685 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff2 +0 -0
- package/_book/gitbook/gitbook-plugin-fontsettings/fontsettings.js +240 -0
- package/_book/gitbook/gitbook-plugin-fontsettings/website.css +291 -0
- package/_book/gitbook/gitbook-plugin-highlight/ebook.css +135 -0
- package/_book/gitbook/gitbook-plugin-highlight/website.css +434 -0
- package/_book/gitbook/gitbook-plugin-lunr/lunr.min.js +7 -0
- package/_book/gitbook/gitbook-plugin-lunr/search-lunr.js +59 -0
- package/_book/gitbook/gitbook-plugin-search/lunr.min.js +7 -0
- package/_book/gitbook/gitbook-plugin-search/search-engine.js +50 -0
- package/_book/gitbook/gitbook-plugin-search/search.css +35 -0
- package/_book/gitbook/gitbook-plugin-search/search.js +213 -0
- package/_book/gitbook/gitbook-plugin-sharing/buttons.js +90 -0
- package/_book/gitbook/gitbook.js +4 -0
- package/_book/gitbook/images/apple-touch-icon-precomposed-152.png +0 -0
- package/_book/gitbook/images/favicon.ico +0 -0
- package/_book/gitbook/style.css +9 -0
- package/_book/gitbook/theme.js +4 -0
- package/_book/index.html +705 -0
- package/_book/intro.md +32 -0
- package/_book/search_index.json +1 -0
- package/book.json +8 -0
- package/build/contracts/AccessControl.json +1 -0
- package/build/contracts/AccessControlEnumerable.json +1 -0
- package/build/contracts/Achievements.json +1 -0
- package/build/contracts/Address.json +1 -0
- package/build/contracts/BalanceHolder.json +1 -0
- package/build/contracts/BalanceHolder_ERC20.json +1 -0
- package/build/contracts/CeilDiv.json +1 -0
- package/build/contracts/Clones.json +1 -0
- package/build/contracts/Context.json +1 -0
- package/build/contracts/Counters.json +1 -0
- package/build/contracts/ERC165.json +1 -0
- package/build/contracts/ERC20.json +1 -0
- package/build/contracts/ERC20Burnable.json +1 -0
- package/build/contracts/ERC20Pausable.json +1 -0
- package/build/contracts/ERC20PresetMinterPauser.json +1 -0
- package/build/contracts/ERC721.json +1 -0
- package/build/contracts/EnumerableMap.json +1 -0
- package/build/contracts/EnumerableSet.json +1 -0
- package/build/contracts/FantasyERC20.json +1 -0
- package/build/contracts/IAccessControl.json +1 -0
- package/build/contracts/IAccessControlEnumerable.json +1 -0
- package/build/contracts/IBalanceHolder_ERC20.json +1 -0
- package/build/contracts/IERC165.json +1 -0
- package/build/contracts/IERC20.json +1 -0
- package/build/contracts/IERC20Metadata.json +1 -0
- package/build/contracts/IERC20Permit.json +1 -0
- package/build/contracts/IERC721.json +1 -0
- package/build/contracts/IERC721Enumerable.json +1 -0
- package/build/contracts/IERC721Metadata.json +1 -0
- package/build/contracts/IERC721Receiver.json +1 -0
- package/build/contracts/IFantasyERC20.json +1 -0
- package/build/contracts/IPredictionMarketV3.json +1 -0
- package/build/contracts/IPredictionMarketV3Factory.json +1 -0
- package/build/contracts/IPredictionMarketV3Manager.json +1 -0
- package/build/contracts/IRealityETH_ERC20.json +1 -0
- package/build/contracts/IRealityETH_IERC20.json +1 -0
- package/build/contracts/IWETH.json +1 -0
- package/build/contracts/LandFactory.json +1 -0
- package/build/contracts/Math.json +1 -0
- package/build/contracts/Migrations.json +1 -0
- package/build/contracts/Ownable.json +1 -0
- package/build/contracts/Pausable.json +1 -0
- package/build/contracts/PredictionMarket.json +1 -0
- package/build/contracts/PredictionMarketV2.json +1 -0
- package/build/contracts/PredictionMarketV3.json +1 -0
- package/build/contracts/PredictionMarketV3Controller.json +1 -0
- package/build/contracts/PredictionMarketV3Factory.json +1 -0
- package/build/contracts/PredictionMarketV3Manager.json +1 -0
- package/build/contracts/PredictionMarketV3Querier.json +1 -0
- package/build/contracts/RealitioERC20.json +1 -0
- package/build/contracts/RealitioForeignArbitrationProxyWithAppeals.json +1 -0
- package/build/contracts/RealitioHomeArbitrationProxy.json +1 -0
- package/build/contracts/RealitioSafeMath256.json +1 -0
- package/build/contracts/RealitioSafeMath32.json +1 -0
- package/build/contracts/RealityETH_ERC20_Factory.json +1 -0
- package/build/contracts/RealityETH_ERC20_v3_0.json +1 -0
- package/build/contracts/ReentrancyGuard.json +1 -0
- package/build/contracts/SafeERC20.json +1 -0
- package/build/contracts/SafeMath.json +1 -0
- package/build/contracts/Strings.json +1 -0
- package/build/contracts/Voting.json +1 -0
- package/build/contracts/WETH9.json +1 -0
- package/build/contracts/test.json +1 -0
- package/cleanContracts.js +22 -0
- package/contracts/FantasyERC20.sol +81 -0
- package/contracts/IFantasyERC20.sol +20 -0
- package/contracts/IPredictionMarketV3.sol +207 -0
- package/contracts/IPredictionMarketV3Factory.sol +10 -0
- package/contracts/IPredictionMarketV3Manager.sol +12 -0
- package/contracts/IRealityETH_ERC20.sol +64 -0
- package/contracts/LandFactory.sol +248 -0
- package/contracts/Migrations.sol +24 -0
- package/contracts/PredictionMarketV3.sol +1332 -0
- package/contracts/PredictionMarketV3Controller.sol +87 -0
- package/contracts/PredictionMarketV3Factory.sol +205 -0
- package/contracts/PredictionMarketV3Manager.sol +45 -0
- package/contracts/PredictionMarketV3Querier.sol +79 -0
- package/contracts/RealityETH_ERC20_Factory.sol +54 -0
- package/contracts/Voting.sol +153 -0
- package/contracts/WETH9.sol +62 -0
- package/hardhat.config.js +4 -0
- package/help.txt +8 -0
- package/index.js +3 -0
- package/migrations/10_deploy_weth.js +5 -0
- package/migrations/11_deploy_full_flow.js +99 -0
- package/migrations/12_deploy_pm_v3_querier.js +7 -0
- package/migrations/13_deploy_pm_v3_factory.js +14 -0
- package/migrations/1_initial_migration.js +5 -0
- package/migrations/2_deploy_erc20.js +10 -0
- package/migrations/3_deploy_realitio.js +11 -0
- package/migrations/4_deploy_pm.js +20 -0
- package/migrations/5_seed_markets.js +51 -0
- package/migrations/6_deploy_achievements.js +5 -0
- package/migrations/7_deploy_voting.js +14 -0
- package/migrations/8_deploy_pm_v2.js +20 -0
- package/migrations/9_seed_markets_v2.js +68 -0
- package/package.json +106 -13
- package/src/Application.js +421 -0
- package/src/interfaces/index.js +19 -0
- package/src/models/AchievementsContract.js +217 -0
- package/src/models/ArbitrationContract.js +69 -0
- package/src/models/ArbitrationProxyContract.js +32 -0
- package/src/models/ERC20Contract.js +156 -0
- package/src/models/FantasyERC20Contract.js +92 -0
- package/src/models/IContract.js +1002 -0
- package/src/models/PolkamarketsSmartAccount.js +100 -0
- package/src/models/PredictionMarketContract.js +562 -0
- package/src/models/PredictionMarketV2Contract.js +830 -0
- package/src/models/PredictionMarketV3Contract.js +256 -0
- package/src/models/PredictionMarketV3ControllerContract.js +102 -0
- package/src/models/PredictionMarketV3FactoryContract.js +96 -0
- package/src/models/PredictionMarketV3ManagerContract.js +111 -0
- package/src/models/PredictionMarketV3QuerierContract.js +24 -0
- package/src/models/RealitioERC20Contract.js +286 -0
- package/src/models/VotingContract.js +182 -0
- package/src/models/WETH9Contract.js +92 -0
- package/src/models/index.js +33 -0
- package/src/utils/Account.js +40 -0
- package/src/utils/Contract.js +120 -0
- package/src/utils/Numbers.js +94 -0
- package/tests/fantasyERC20Contract.js +225 -0
- package/tests/index.js +10 -0
- package/tests/predictionMarketContract.js +466 -0
- package/tests/predictionMarketV2Contract.js +1042 -0
- package/tests/predictionMarketV3Contract.js +1079 -0
- package/tests/predictionMarketV3ControllerContract.js +613 -0
- package/tests/predictionMarketV3FactoryContract.js +469 -0
- package/tests/predictionMarketV3ManagerContract.js +610 -0
- package/tests/utils.js +16 -0
- package/tests/votingContract.js +490 -0
- package/tooling/docs/jsdoc.json +6 -0
- package/truffle-config.js +134 -0
- package/polkamarkets.js +0 -436
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
class Contract {
|
|
3
|
+
constructor(web3, contract_json, address) {
|
|
4
|
+
this.web3 = web3;
|
|
5
|
+
this.json = contract_json;
|
|
6
|
+
this.abi = contract_json.abi;
|
|
7
|
+
this.address = address;
|
|
8
|
+
this.contract = new web3.eth.Contract(contract_json.abi, address);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async deploy(account, abi, byteCode, args = [], callback = () => { }) {
|
|
12
|
+
this.contract = new this.web3.eth.Contract(abi);
|
|
13
|
+
if (account) {
|
|
14
|
+
const data = this.contract.deploy({
|
|
15
|
+
data: byteCode,
|
|
16
|
+
arguments: args,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const rawTransaction = (await account.getAccount().signTransaction({
|
|
20
|
+
data: data.encodeABI(),
|
|
21
|
+
from: account.getAddress(),
|
|
22
|
+
gas: 5913388,
|
|
23
|
+
})).rawTransaction;
|
|
24
|
+
|
|
25
|
+
return await this.web3.eth.sendSignedTransaction(rawTransaction);
|
|
26
|
+
} else {
|
|
27
|
+
const accounts = await this.web3.eth.getAccounts();
|
|
28
|
+
const res = await this.__metamaskDeploy({
|
|
29
|
+
byteCode,
|
|
30
|
+
args,
|
|
31
|
+
acc: accounts[0],
|
|
32
|
+
callback,
|
|
33
|
+
});
|
|
34
|
+
this.address = res.contractAddress;
|
|
35
|
+
return res;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async __metamaskDeploy({ byteCode, args, acc, callback = () => { } }) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
try {
|
|
42
|
+
this.getContract()
|
|
43
|
+
.deploy({
|
|
44
|
+
data: byteCode,
|
|
45
|
+
arguments: args,
|
|
46
|
+
}).send({ from: acc })
|
|
47
|
+
.on('confirmation', (confirmationNumber, receipt) => {
|
|
48
|
+
callback(confirmationNumber)
|
|
49
|
+
if (confirmationNumber > 0) {
|
|
50
|
+
resolve(receipt);
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
.on('error', err => { reject(err) });
|
|
54
|
+
} catch (err) {
|
|
55
|
+
reject(err);
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async use(contract_json, address) {
|
|
61
|
+
this.json = contract_json;
|
|
62
|
+
this.abi = contract_json.abi;
|
|
63
|
+
this.address = address ? address : this.address;
|
|
64
|
+
this.contract = new this.web3.eth.Contract(
|
|
65
|
+
contract_json.abi,
|
|
66
|
+
this.address
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async send(account, byteCode, value = '0x0', callback = () => { }) {
|
|
71
|
+
return new Promise(async (resolve, reject) => {
|
|
72
|
+
let gasPrice;
|
|
73
|
+
try {
|
|
74
|
+
gasPrice = await this.web3.eth.getGasPrice();
|
|
75
|
+
gasPrice *= 2;
|
|
76
|
+
} catch (err) {
|
|
77
|
+
// should be non-blocking, defaulting to 10 gwei
|
|
78
|
+
gasPrice = '10000000000';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let tx = {
|
|
82
|
+
data: byteCode,
|
|
83
|
+
from: account.address,
|
|
84
|
+
to: this.address,
|
|
85
|
+
gas: 4430000,
|
|
86
|
+
gasPrice,
|
|
87
|
+
value: value ? value : '0x0'
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let result = await account.signTransaction(tx);
|
|
91
|
+
this.web3.eth.sendSignedTransaction(result.rawTransaction)
|
|
92
|
+
.on('confirmation', (confirmationNumber, receipt) => {
|
|
93
|
+
callback(confirmationNumber);
|
|
94
|
+
if (confirmationNumber > 0) {
|
|
95
|
+
resolve(receipt);
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
.on('error', err => { reject(err) });
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getContract() {
|
|
104
|
+
return this.contract;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getABI() {
|
|
108
|
+
return this.abi;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getJSON() {
|
|
112
|
+
return this.json;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getAddress() {
|
|
116
|
+
return this.address;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = Contract;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const moment = require('moment');
|
|
2
|
+
|
|
3
|
+
Number.prototype.noExponents = function () {
|
|
4
|
+
var data = String(this).split(/[eE]/)
|
|
5
|
+
if (data.length == 1) return data[0]
|
|
6
|
+
|
|
7
|
+
var z = '',
|
|
8
|
+
sign = this < 0 ? '-' : '',
|
|
9
|
+
str = data[0].replace('.', ''),
|
|
10
|
+
mag = Number(data[1]) + 1
|
|
11
|
+
|
|
12
|
+
if (mag < 0) {
|
|
13
|
+
z = sign + '0.'
|
|
14
|
+
while (mag++) z += '0'
|
|
15
|
+
return z + str.replace(/^\-/, '')
|
|
16
|
+
}
|
|
17
|
+
mag -= str.length
|
|
18
|
+
while (mag--) z += '0'
|
|
19
|
+
return str + z
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class numbers {
|
|
23
|
+
constructor() {}
|
|
24
|
+
|
|
25
|
+
fromDayMonthYear(date) {
|
|
26
|
+
let mom = moment().dayOfYear(date.day)
|
|
27
|
+
mom.set('hour', date.hour)
|
|
28
|
+
mom.set('year', date.year)
|
|
29
|
+
return mom.format('ddd, hA')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fromHex(hex){
|
|
33
|
+
return hex.toString();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toFloat(number) {
|
|
37
|
+
return parseFloat(parseFloat(number).toFixed(2))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
timeToSmartContractTime(time) {
|
|
41
|
+
return parseInt(new Date(time).getTime() / 1000)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
toDate(date) {
|
|
45
|
+
let mom = moment().dayOfYear(date.day)
|
|
46
|
+
mom.set('hour', date.hour)
|
|
47
|
+
mom.set('year', date.year)
|
|
48
|
+
return mom.unix()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toSmartContractDecimals(value, decimals) {
|
|
52
|
+
let numberWithNoExponents = new Number((Number(value) * 10 ** decimals).toFixed(0)).noExponents();
|
|
53
|
+
return numberWithNoExponents;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fromBigNumberToInteger(value, decimals = 18) {
|
|
57
|
+
return Math.round((value / Math.pow(10, decimals)) * 1000000000000000000);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fromDecimals(value, decimals) {
|
|
61
|
+
return Number(parseFloat(value / 10 ** decimals).toPrecision(decimals)).noExponents();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fromDecimalsNumber(value, decimals) {
|
|
65
|
+
const number = Number(parseFloat(value / 10 ** decimals).toPrecision(decimals)).noExponents();
|
|
66
|
+
return Number(number);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fromExponential(x) {
|
|
70
|
+
if (Math.abs(x) < 1.0) {
|
|
71
|
+
var e = parseInt(x.toString().split('e-')[1])
|
|
72
|
+
if (e) {
|
|
73
|
+
x *= Math.pow(10, e - 1)
|
|
74
|
+
x = '0.' + new Array(e).join('0') + x.toString().substring(2)
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
var e = parseInt(x.toString().split('+')[1])
|
|
78
|
+
if (e > 20) {
|
|
79
|
+
e -= 20
|
|
80
|
+
x /= Math.pow(10, e)
|
|
81
|
+
x += new Array(e + 1).join('0')
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return x
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
nullHash() {
|
|
88
|
+
return '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let Numbers = new numbers()
|
|
93
|
+
|
|
94
|
+
module.exports = Numbers;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { expect } from 'chai';
|
|
4
|
+
|
|
5
|
+
import { mochaAsync } from './utils';
|
|
6
|
+
import { Application } from '..';
|
|
7
|
+
const Numbers = require("../src/utils/Numbers");
|
|
8
|
+
|
|
9
|
+
context('FantasyERC20 Contract', async () => {
|
|
10
|
+
require('dotenv').config();
|
|
11
|
+
|
|
12
|
+
const TOKEN_AMOUNT_TO_CLAIM = '10000';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const USER1_ADDRESS = process.env.TEST_USER1_ADDRESS;
|
|
16
|
+
const USER1_PRIVATE_KEY = process.env.TEST_USER1_PRIVATE_KEY;
|
|
17
|
+
const USER2_ADDRESS = process.env.TEST_USER2_ADDRESS;
|
|
18
|
+
const USER2_PRIVATE_KEY = process.env.TEST_USER2_PRIVATE_KEY;
|
|
19
|
+
const TOKEN_MANAGER_ADDRESS = process.env.TEST_USER3_ADDRESS;
|
|
20
|
+
const TOKEN_MANAGER_PRIVATE_KEY = process.env.TEST_USER3_PRIVATE_KEY;
|
|
21
|
+
|
|
22
|
+
let app;
|
|
23
|
+
let fantasyERC20ContractAddress;
|
|
24
|
+
|
|
25
|
+
let user1FantasyERC20Contract;
|
|
26
|
+
let user2FantasyERC20Contract2;
|
|
27
|
+
let tokenManagerfantasyERC20Contract;
|
|
28
|
+
|
|
29
|
+
context('Contract Deployment', async () => {
|
|
30
|
+
it('should start the Application', mochaAsync(async () => {
|
|
31
|
+
app = new Application({
|
|
32
|
+
web3Provider: process.env.WEB3_PROVIDER,
|
|
33
|
+
web3PrivateKey: USER1_PRIVATE_KEY,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(app).to.not.equal(null);
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
it('should deploy FantasyERC20 Contract', mochaAsync(async () => {
|
|
40
|
+
// Create Contract
|
|
41
|
+
user1FantasyERC20Contract = app.getFantasyERC20Contract({});
|
|
42
|
+
// Deploy
|
|
43
|
+
await user1FantasyERC20Contract.deploy({
|
|
44
|
+
params: [
|
|
45
|
+
'Fantasy',
|
|
46
|
+
'FNTS',
|
|
47
|
+
Numbers.toSmartContractDecimals(TOKEN_AMOUNT_TO_CLAIM, 18),
|
|
48
|
+
TOKEN_MANAGER_ADDRESS,
|
|
49
|
+
'0x0000000000000000000000000000000000000000',
|
|
50
|
+
'0x0000000000000000000000000000000000000000'
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
fantasyERC20ContractAddress = user1FantasyERC20Contract.getAddress();
|
|
55
|
+
|
|
56
|
+
expect(fantasyERC20ContractAddress).to.not.equal(null);
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
context('Claim Tokens', async () => {
|
|
61
|
+
it('should claim tokens for address', mochaAsync(async () => {
|
|
62
|
+
|
|
63
|
+
app = new Application({
|
|
64
|
+
web3Provider: process.env.WEB3_PROVIDER,
|
|
65
|
+
web3PrivateKey: USER2_PRIVATE_KEY,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
user2FantasyERC20Contract2 = app.getFantasyERC20Contract({ contractAddress: fantasyERC20ContractAddress });
|
|
69
|
+
await user2FantasyERC20Contract2.__init__();
|
|
70
|
+
|
|
71
|
+
let user2HasClaimedTokens;
|
|
72
|
+
let user2TokenAmount;
|
|
73
|
+
let totalSupply;
|
|
74
|
+
let isApproved;
|
|
75
|
+
|
|
76
|
+
// check if address hasn't claimed tokens
|
|
77
|
+
user2HasClaimedTokens = await user2FantasyERC20Contract2.hasUserClaimedTokens({ address: USER2_ADDRESS });
|
|
78
|
+
expect(user2HasClaimedTokens).to.equal(false);
|
|
79
|
+
|
|
80
|
+
user2TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER2_ADDRESS);
|
|
81
|
+
expect(user2TokenAmount).to.equal('0');
|
|
82
|
+
|
|
83
|
+
totalSupply = await user2FantasyERC20Contract2.totalSupply();
|
|
84
|
+
expect(totalSupply).to.equal('0');
|
|
85
|
+
|
|
86
|
+
isApproved = await user2FantasyERC20Contract2.isApproved({ address: USER2_ADDRESS, amount: TOKEN_AMOUNT_TO_CLAIM, spenderAddress: TOKEN_MANAGER_ADDRESS });
|
|
87
|
+
expect(isApproved).to.equal(false);
|
|
88
|
+
|
|
89
|
+
// claim tokens
|
|
90
|
+
const res = await user2FantasyERC20Contract2.claimAndApproveTokens();
|
|
91
|
+
expect(res.status).to.equal(true);
|
|
92
|
+
|
|
93
|
+
// check if address hasn't claimed tokens
|
|
94
|
+
user2HasClaimedTokens = await user2FantasyERC20Contract2.hasUserClaimedTokens({ address: USER2_ADDRESS });
|
|
95
|
+
expect(user2HasClaimedTokens).to.equal(true);
|
|
96
|
+
|
|
97
|
+
user2TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER2_ADDRESS);
|
|
98
|
+
expect(user2TokenAmount).to.equal(
|
|
99
|
+
TOKEN_AMOUNT_TO_CLAIM
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
totalSupply = await user2FantasyERC20Contract2.totalSupply();
|
|
103
|
+
expect(totalSupply).to.equal(TOKEN_AMOUNT_TO_CLAIM);
|
|
104
|
+
|
|
105
|
+
isApproved = await user2FantasyERC20Contract2.isApproved({ address: USER2_ADDRESS, amount: TOKEN_AMOUNT_TO_CLAIM, spenderAddress: TOKEN_MANAGER_ADDRESS });
|
|
106
|
+
expect(isApproved).to.equal(true);
|
|
107
|
+
}));
|
|
108
|
+
|
|
109
|
+
it('should not claim tokens for address that has already claimed tokens', mochaAsync(async () => {
|
|
110
|
+
let user2HasClaimedTokens;
|
|
111
|
+
let user2TokenAmount;
|
|
112
|
+
|
|
113
|
+
// check if address has already claimed tokens
|
|
114
|
+
user2HasClaimedTokens = await user2FantasyERC20Contract2.hasUserClaimedTokens({ address: USER2_ADDRESS });
|
|
115
|
+
expect(user2HasClaimedTokens).to.equal(true);
|
|
116
|
+
|
|
117
|
+
user2TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER2_ADDRESS);
|
|
118
|
+
expect(user2TokenAmount).to.equal(TOKEN_AMOUNT_TO_CLAIM);
|
|
119
|
+
|
|
120
|
+
// claim tokens
|
|
121
|
+
let res;
|
|
122
|
+
try {
|
|
123
|
+
res = await user2FantasyERC20Contract2.claimAndApproveTokens();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
res = { status: false };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
expect(res.status).to.equal(false);
|
|
129
|
+
// TODO: check if error is correct
|
|
130
|
+
// expect(res.reason).to.equal('FantasyERC20: address already claimed the tokens');
|
|
131
|
+
|
|
132
|
+
user2HasClaimedTokens = await user2FantasyERC20Contract2.hasUserClaimedTokens({ address: USER2_ADDRESS });
|
|
133
|
+
expect(user2HasClaimedTokens).to.equal(true);
|
|
134
|
+
|
|
135
|
+
user2TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER2_ADDRESS);
|
|
136
|
+
expect(user2TokenAmount).to.equal(TOKEN_AMOUNT_TO_CLAIM);
|
|
137
|
+
|
|
138
|
+
}));
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
context('Transfer Tokens', async () => {
|
|
142
|
+
it('should allow to transfer tokens between an address and the token manager', mochaAsync(async () => {
|
|
143
|
+
// transfer from address to token manager
|
|
144
|
+
const tokenAmountToTransfer = 500;
|
|
145
|
+
let user2TokenAmount;
|
|
146
|
+
let managerTokenAmount;
|
|
147
|
+
|
|
148
|
+
user2TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER2_ADDRESS);
|
|
149
|
+
expect(user2TokenAmount).to.equal(TOKEN_AMOUNT_TO_CLAIM);
|
|
150
|
+
|
|
151
|
+
managerTokenAmount = await user2FantasyERC20Contract2.getTokenAmount(TOKEN_MANAGER_ADDRESS);
|
|
152
|
+
expect(managerTokenAmount).to.equal('0');
|
|
153
|
+
|
|
154
|
+
let res = await user2FantasyERC20Contract2.transferTokenAmount({
|
|
155
|
+
toAddress: TOKEN_MANAGER_ADDRESS,
|
|
156
|
+
tokenAmount: tokenAmountToTransfer,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(res.status).to.equal(true);
|
|
160
|
+
|
|
161
|
+
user2TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER2_ADDRESS);
|
|
162
|
+
expect(parseFloat(user2TokenAmount).toFixed(0)).to.equal((TOKEN_AMOUNT_TO_CLAIM - tokenAmountToTransfer).toFixed(0));
|
|
163
|
+
|
|
164
|
+
managerTokenAmount = await user2FantasyERC20Contract2.getTokenAmount(TOKEN_MANAGER_ADDRESS);
|
|
165
|
+
expect(managerTokenAmount).to.equal(tokenAmountToTransfer.toFixed(0));
|
|
166
|
+
|
|
167
|
+
// transfer back from manager to address
|
|
168
|
+
app = new Application({
|
|
169
|
+
web3Provider: process.env.WEB3_PROVIDER,
|
|
170
|
+
web3PrivateKey: TOKEN_MANAGER_PRIVATE_KEY,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
tokenManagerfantasyERC20Contract = app.getFantasyERC20Contract({ contractAddress: fantasyERC20ContractAddress });
|
|
174
|
+
await tokenManagerfantasyERC20Contract.__init__();
|
|
175
|
+
|
|
176
|
+
res = await tokenManagerfantasyERC20Contract.transferTokenAmount({
|
|
177
|
+
toAddress: USER2_ADDRESS,
|
|
178
|
+
tokenAmount: tokenAmountToTransfer,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
expect(res.status).to.equal(true);
|
|
182
|
+
|
|
183
|
+
user2TokenAmount = await tokenManagerfantasyERC20Contract.getTokenAmount(USER2_ADDRESS);
|
|
184
|
+
expect(user2TokenAmount).to.equal(TOKEN_AMOUNT_TO_CLAIM);
|
|
185
|
+
|
|
186
|
+
managerTokenAmount = await tokenManagerfantasyERC20Contract.getTokenAmount(TOKEN_MANAGER_ADDRESS);
|
|
187
|
+
expect(managerTokenAmount).to.equal('0');
|
|
188
|
+
|
|
189
|
+
}));
|
|
190
|
+
|
|
191
|
+
it('should not allow to transfer tokens between 2 addresses that are not the token manager', mochaAsync(async () => {
|
|
192
|
+
|
|
193
|
+
const tokenAmountToTransfer = 500;
|
|
194
|
+
let user1TokenAmount;
|
|
195
|
+
let user2TokenAmount;
|
|
196
|
+
|
|
197
|
+
user2TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER2_ADDRESS);
|
|
198
|
+
expect(user2TokenAmount).to.equal(TOKEN_AMOUNT_TO_CLAIM);
|
|
199
|
+
|
|
200
|
+
user1TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER1_ADDRESS);
|
|
201
|
+
expect(user1TokenAmount).to.equal('0');
|
|
202
|
+
|
|
203
|
+
let res;
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
res = await user2FantasyERC20Contract2.transferTokenAmount({
|
|
207
|
+
toAddress: USER1_ADDRESS,
|
|
208
|
+
tokenAmount: tokenAmountToTransfer,
|
|
209
|
+
});
|
|
210
|
+
} catch (error) {
|
|
211
|
+
res = { status: false };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
expect(res.status).to.equal(false);
|
|
215
|
+
// TODO: check if error is correct
|
|
216
|
+
// expect(res.reason).to.equal('FantasyERC20: token transfer not allowed between the addresses');
|
|
217
|
+
|
|
218
|
+
user2TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER2_ADDRESS);
|
|
219
|
+
expect(parseFloat(user2TokenAmount).toFixed(0)).to.equal(TOKEN_AMOUNT_TO_CLAIM);
|
|
220
|
+
|
|
221
|
+
user1TokenAmount = await user2FantasyERC20Contract2.getTokenAmount(USER1_ADDRESS);
|
|
222
|
+
expect(user1TokenAmount).to.equal('0');
|
|
223
|
+
}));
|
|
224
|
+
});
|
|
225
|
+
});
|
package/tests/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
context('Unit Tests', () => {
|
|
2
|
+
require('./predictionMarketContract');
|
|
3
|
+
require('./predictionMarketV2Contract');
|
|
4
|
+
require('./predictionMarketV3Contract');
|
|
5
|
+
require('./predictionMarketV3ManagerContract');
|
|
6
|
+
require('./predictionMarketV3ControllerContract');
|
|
7
|
+
require('./predictionMarketV3FactoryContract');
|
|
8
|
+
require('./fantasyERC20Contract');
|
|
9
|
+
require('./votingContract');
|
|
10
|
+
});
|