-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
placeSellTokenOrder & placeBuyTokenOrder #42
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b29791
placeSellTokenOrder & placeBuyTokenOrder
szerintedmi 05a53c4
Merge branch 'staging' into placeorder
szerintedmi a4a7cdf
remove Exchange.tokenPeggedSymbol prop (use Exchange.token.peggedSymb…
szerintedmi 5b8662b
remove Exchange.decimalsDiv (use Exchange.token.decimalsDiv)
szerintedmi ddb1121
use BN for placeBuyTokenOrder & placeSellTokenOrder
szerintedmi 850aa96
remove unused imports
szerintedmi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,134 @@ | ||
const { BN } = require("bn.js"); | ||
const { assert } = require("chai"); | ||
const { takeSnapshot, revertSnapshot } = require("./testHelpers/ganache.js"); | ||
const { Augmint, utils } = require("../dist/index.js"); | ||
const { assertEvent } = require("./testHelpers/events"); | ||
const { issueToken } = require("./testHelpers/token"); | ||
const { TransactionSendError } = Augmint.Errors; | ||
const loadEnv = require("./testHelpers/loadEnv.js"); | ||
const config = loadEnv(); | ||
if (config.LOG) { | ||
utils.logger.level = config.LOG; | ||
} | ||
|
||
describe("place orders - invalid args", () => { | ||
let augmint = null; | ||
let exchange = null; | ||
|
||
before(async () => { | ||
augmint = await Augmint.create(config); | ||
exchange = augmint.exchange; | ||
}); | ||
|
||
it("placeBuyTokenOrder should allow only integer for price", () => { | ||
assert.throws( | ||
() => exchange.placeBuyTokenOrder(1.1, 10000).send({ from: augmint.ethereumConnection.accounts[0] }), | ||
TransactionSendError, | ||
/invalid number value/ | ||
); | ||
}); | ||
|
||
it("placeSellTokenOrder should allow only integer for price", () => { | ||
assert.throws( | ||
() => exchange.placeSellTokenOrder(1.1, 10000).send({ from: augmint.ethereumConnection.accounts[0] }), | ||
TransactionSendError, | ||
/invalid number value/ | ||
); | ||
}); | ||
|
||
it("placeSellTokenOrder should allow only integer for tokenamount", () => { | ||
assert.throws( | ||
() => exchange.placeSellTokenOrder(1000000, 100.121).send({ from: augmint.ethereumConnection.accounts[0] }), | ||
TransactionSendError, | ||
/invalid number value/ | ||
); | ||
}); | ||
}); | ||
|
||
describe("place orders - onchain", () => { | ||
let augmint = null; | ||
let exchange = null; | ||
let accounts; | ||
let snapshotId; | ||
|
||
beforeEach(async () => { | ||
snapshotId = await takeSnapshot(augmint.ethereumConnection.web3); | ||
}); | ||
|
||
afterEach(async () => { | ||
await revertSnapshot(augmint.ethereumConnection.web3, snapshotId); | ||
}); | ||
|
||
before(async () => { | ||
augmint = await Augmint.create(config); | ||
exchange = augmint.exchange; | ||
accounts = augmint.ethereumConnection.accounts; | ||
}); | ||
|
||
it("placeBuyTokenOrder success", async () => { | ||
const maker = accounts[1]; | ||
const price = new BN(1.01 * Augmint.constants.PPM_DIV); | ||
const amount = new BN(2000000000); | ||
const tx = exchange.placeBuyTokenOrder(price, amount); | ||
const txReceipt = await tx.send({ from: maker }).getTxReceipt(); | ||
|
||
assert(txReceipt.status); | ||
// event NewOrder(uint64 indexed orderId, address indexed maker, uint32 price, uint tokenAmount, uint weiAmount); | ||
await assertEvent(exchange.instance, "NewOrder", { | ||
orderId: x => parseInt(x), | ||
maker: maker, | ||
price: price.toString(), | ||
tokenAmount: "0", | ||
weiAmount: amount.toString() | ||
}); | ||
}); | ||
|
||
it("placeSellTokenOrder success", async () => { | ||
const maker = accounts[1]; | ||
const price = new BN(1.02 * Augmint.constants.PPM_DIV); | ||
const amount = new BN(1099); | ||
|
||
await issueToken(augmint, accounts[0], maker, amount); | ||
|
||
const tx = exchange.placeSellTokenOrder(price, amount); | ||
const txReceipt = await tx.send({ from: maker }).getTxReceipt(); | ||
|
||
assert(txReceipt.status); | ||
|
||
// event NewOrder(uint64 indexed orderId, address indexed maker, uint32 price, uint tokenAmount, uint weiAmount); | ||
await assertEvent(exchange.instance, "NewOrder", { | ||
orderId: x => parseInt(x), | ||
maker: maker, | ||
price: price.toString(), | ||
tokenAmount: amount.toString(), | ||
weiAmount: "0" | ||
}); | ||
}); | ||
}); | ||
|
||
describe("cancel order ", () => { | ||
let augmint = null; | ||
let exchange = null; | ||
let snapshotId; | ||
|
||
before(async () => { | ||
augmint = await Augmint.create(config); | ||
exchange = augmint.exchange; | ||
}); | ||
|
||
beforeEach(async () => { | ||
snapshotId = await takeSnapshot(augmint.ethereumConnection.web3); | ||
}); | ||
|
||
afterEach(async () => { | ||
await revertSnapshot(augmint.ethereumConnection.web3, snapshotId); | ||
}); | ||
|
||
it("should cancel a buy order"); | ||
|
||
it("should cancel a sell order"); | ||
|
||
it("cancel sell order should throw if order id is invalid"); | ||
|
||
it("cancel buy order should throw if order id is invalid"); | ||
}); |
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,19 @@ | ||
const { mine } = require("./ganache.js"); | ||
|
||
module.exports = { issueToken }; | ||
|
||
async function issueToken(augmint, sender, to, _amount) { | ||
const amount = (_amount * (await augmint.token.decimalsDiv)).toString(); | ||
const MONETARYSUPERVISOR_PERMISSION = augmint.ethereumConnection.web3.utils.asciiToHex("MonetarySupervisor"); | ||
const token = (await augmint.token).instance; | ||
const web3 = augmint.ethereumConnection.web3; | ||
|
||
token.methods.grantPermission(sender, MONETARYSUPERVISOR_PERMISSION).send({ from: sender }); | ||
await mine(web3, 1); // we mine instead of waiting for blockTimeout to mine in ganache to speed up tests | ||
|
||
token.methods.issueTo(to, amount).send({ from: sender }); | ||
await mine(web3, 1); | ||
|
||
token.methods.revokePermission(sender, MONETARYSUPERVISOR_PERMISSION).send({ from: sender }); | ||
await mine(web3, 1); | ||
} |
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 |
---|---|---|
|
@@ -357,7 +357,7 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215" | ||
integrity sha1-UzRK2xRhehP26N0s4okF0cC6MhU= | ||
|
||
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.6, bn.js@^4.4.0: | ||
bn.js@4.11.8, bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.6, bn.js@^4.4.0: | ||
version "4.11.8" | ||
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" | ||
integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA== | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this some autoformatting? did the settings change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep i've noticed. it's happened before too. I suspect that @rszaloki doesn't have prettier format on save set or something else different in our editor. We should make sure we sync our setting