-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
220 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* ISC License (ISC) | ||
* Copyright (c) 2018 aeternity developers | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
* PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
require('it-each')({ testPerIteration: true }); | ||
const { Universal, MemoryAccount, Node } = require('@aeternity/aepp-sdk'); | ||
const BONDING_CURVE_LINEAR_CONTRACT = utils.readFileRelative( | ||
'./contracts/BondCurveLinear.aes', | ||
'utf-8', | ||
); | ||
const testData = require('./data'); | ||
|
||
const config = { | ||
url: 'http://localhost:3001/', | ||
internalUrl: 'http://localhost:3001/', | ||
compilerUrl: 'http://localhost:3080', | ||
}; | ||
|
||
describe('Bonding Curve Contract', () => { | ||
let client, contract; | ||
|
||
before(async () => { | ||
client = await Universal({ | ||
nodes: [ | ||
{ | ||
name: 'devnetNode', | ||
instance: await Node(config), | ||
}, | ||
], | ||
accounts: [ | ||
MemoryAccount({ | ||
keypair: wallets[0], | ||
}), | ||
], | ||
networkId: 'ae_devnet', | ||
compilerUrl: config.compilerUrl, | ||
}); | ||
}); | ||
|
||
it('Deploying Bond Contract', async () => { | ||
contract = await client.getContractInstance(BONDING_CURVE_LINEAR_CONTRACT); | ||
const init = await contract.methods.init(); | ||
assert.equal(init.result.returnType, 'ok'); | ||
}); | ||
|
||
describe('Buy current price tests', () => { | ||
it.each( | ||
[...testData], | ||
'Should get buy price for supply %s', | ||
['element'], | ||
(p, next) => { | ||
contract.methods.buy_price(p.totalSupply).then((result) => { | ||
assert.equal( | ||
result.decodedResult, | ||
p.totalSupply + 1, | ||
`Buy price incorrect for supply: ${p.totalSupply}`, | ||
); | ||
next(); | ||
}); | ||
}, | ||
); | ||
}); | ||
|
||
describe('Sell current price tests', () => { | ||
it.each( | ||
[...testData], | ||
'Should get sell price for supply %s', | ||
['element'], | ||
(p, next) => { | ||
contract.methods.sell_price(p.totalSupply).then((result) => { | ||
assert.equal( | ||
result.decodedResult, | ||
p.totalSupply, | ||
`Sell price incorrect for supply: ${p.totalSupply}`, | ||
); | ||
next(); | ||
}); | ||
}, | ||
); | ||
}); | ||
|
||
describe('Calculate Buy price tests', () => { | ||
it.each( | ||
[...testData], | ||
'Should calculate buy price for supply %s', | ||
['element'], | ||
(p, next) => { | ||
contract.methods | ||
.calculate_buy_price(p.totalSupply, p.buy.amount) | ||
.then((result) => { | ||
assert.equal( | ||
result.decodedResult, | ||
p.buy.aettos, | ||
`Calculation for buy price incorrect for: supply=${p.totalSupply} buy_amount=${p.buy.amount}`, | ||
); | ||
next(); | ||
}); | ||
}, | ||
); | ||
}); | ||
|
||
describe('Sell price tests', () => { | ||
it.each( | ||
[...testData], | ||
'Should calculate sell return for supply %s', | ||
['element'], | ||
(p, next) => { | ||
if (p.totalSupply >= p.sell.amount) { | ||
contract.methods | ||
.calculate_sell_return(p.totalSupply, p.sell.amount) | ||
.then((result) => { | ||
assert.equal( | ||
result.decodedResult, | ||
p.sell.aettos, | ||
`Calculation for sell price incorrect for: supply=${p.totalSupply} sell_amount=${p.sell.amount}`, | ||
); | ||
next(); | ||
}); | ||
} else { | ||
contract.methods | ||
.calculate_sell_return(p.totalSupply, p.sell.amount) | ||
.then((result) => { | ||
assert.equal( | ||
result.decodedResult, | ||
p.sell.aettos, | ||
`Calculation for sell price incorrect for: supply=${p.totalSupply} sell_amount=${p.sell.amount}`, | ||
); | ||
next(); | ||
}) | ||
.catch((e) => { | ||
if ( | ||
e.decodedError.indexOf( | ||
'ERROR_SELL_INSUFFICIENT_TOTAL_SUPPLY' > -1, | ||
) | ||
) { | ||
next(); | ||
} | ||
}); | ||
} | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module.exports = [ | ||
{ | ||
totalSupply: 0, | ||
buy: { amount: 1123, aettos: 631688 }, | ||
sell: { amount: 1, aettos: 0 }, | ||
}, | ||
{ | ||
totalSupply: 2, | ||
buy: { amount: 44234, aettos: 978456080 }, | ||
sell: { amount: 11231, aettos: 0 }, | ||
}, | ||
{ | ||
totalSupply: 3, | ||
buy: { amount: 118723, aettos: 7048050257 }, | ||
sell: { amount: 15523, aettos: 0 }, | ||
}, | ||
{ | ||
totalSupply: 7, | ||
buy: { amount: 747239841, aettos: '279183695966771369' }, | ||
sell: { amount: 3123123, aettos: 0 }, | ||
}, | ||
{ | ||
totalSupply: 42, | ||
buy: { amount: 2348231, aettos: 2757195388614 }, | ||
sell: { amount: 234923, aettos: 0 }, | ||
}, | ||
{ | ||
totalSupply: 144, | ||
buy: { amount: 2349241, aettos: 2759807277986 }, | ||
sell: { amount: 2349921, aettos: 0 }, | ||
}, | ||
{ | ||
totalSupply: 256, | ||
buy: { amount: 5437811, aettos: 14786291753288 }, | ||
sell: { amount: 42394, aettos: 0 }, | ||
}, | ||
{ | ||
totalSupply: 1237, | ||
buy: { amount: 2349021, aettos: 2761857917219 }, | ||
sell: { amount: 1283712, aettos: 0 }, | ||
}, | ||
{ | ||
totalSupply: 88321, | ||
buy: { amount: 32095831, aettos: 517905951775863 }, | ||
sell: { amount: 13882, aettos: 1129717160 }, | ||
}, | ||
{ | ||
totalSupply: 9238123, | ||
buy: { amount: 1238171, aettos: 12204910943825 }, | ||
sell: { amount: 142349, aettos: 1304905952027 }, | ||
}, | ||
{ | ||
totalSupply: 2138123173912, | ||
buy: { amount: 2349241, aettos: '5022969382673188074' }, | ||
sell: { amount: 49214234, aettos: '105224883181313760030' }, | ||
}, | ||
{ | ||
totalSupply: 123987123123817, | ||
buy: { amount: 1223492, aettos: '151697253993472669488' }, | ||
sell: { amount: 2349293492, aettos: '291279381856630211521932' }, | ||
}, | ||
]; |
This file was deleted.
Oops, something went wrong.
Empty file.