This repository was archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
CancelOrder and specs. Added orderFills and orderCancels getters to C… #84
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -156,6 +156,16 @@ contract("CoreIssuanceOrder", (accounts) => { | |
assertTokenBalance(setToken, existingBalance.add(subjectQuantityToIssue), signerAddress); | ||
}); | ||
|
||
it("marks the correct amount as filled in orderFills mapping", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure your test pulls the value before (even if it's 0), and checks that the ending value is what you intended. See: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool |
||
const preFilled = await core.orderFills.callAsync(issuanceOrderParams.orderHash); | ||
expect(preFilled).to.be.bignumber.equal(ZERO); | ||
|
||
await subject(); | ||
|
||
const filled = await core.orderFills.callAsync(issuanceOrderParams.orderHash); | ||
expect(filled).to.be.bignumber.equal(subjectQuantityToIssue); | ||
}); | ||
|
||
describe("when the quantity to issue is not positive", async () => { | ||
beforeEach(async () => { | ||
subjectQuantityToIssue = ZERO; | ||
|
@@ -236,4 +246,112 @@ contract("CoreIssuanceOrder", (accounts) => { | |
}); | ||
}); | ||
}); | ||
|
||
describe("#cancelOrder", async () => { | ||
let subjectCaller: Address; | ||
let subjectQuantityToCancel: BigNumber; | ||
let subjectExchangeOrdersData: Bytes32; | ||
|
||
const naturalUnit: BigNumber = ether(2); | ||
let components: StandardTokenMockContract[] = []; | ||
let componentUnits: BigNumber[]; | ||
let setToken: SetTokenContract; | ||
let signerAddress: Address; | ||
let componentAddresses: Address[]; | ||
|
||
let issuanceOrderParams: any; | ||
|
||
beforeEach(async () => { | ||
signerAddress = signerAccount; | ||
|
||
components = await erc20Wrapper.deployTokensAsync(2, signerAddress); //For current purposes issue to maker/signer | ||
await erc20Wrapper.approveTransfersAsync(components, transferProxy.address, signerAddress); | ||
|
||
componentAddresses = _.map(components, (token) => token.address); | ||
componentUnits = _.map(components, () => ether(4)); // Multiple of naturalUnit | ||
setToken = await coreWrapper.createSetTokenAsync( | ||
core, | ||
setTokenFactory.address, | ||
componentAddresses, | ||
componentUnits, | ||
naturalUnit, | ||
); | ||
|
||
await coreWrapper.registerDefaultExchanges(core); | ||
|
||
subjectCaller = signerAccount; | ||
subjectQuantityToCancel = ether(2); | ||
issuanceOrderParams = await generateFillOrderParameters(setToken.address, signerAddress, signerAddress, componentAddresses[0]); | ||
subjectExchangeOrdersData = generateOrdersDataForOrderCount(3); | ||
}); | ||
|
||
async function subject(): Promise<string> { | ||
return core.cancelOrder.sendTransactionAsync( | ||
issuanceOrderParams.addresses, | ||
issuanceOrderParams.values, | ||
subjectQuantityToCancel, | ||
{ from: subjectCaller }, | ||
); | ||
} | ||
|
||
it("marks the correct amount as canceled in orderCancels mapping", async () => { | ||
const preCanceled = await core.orderCancels.callAsync(issuanceOrderParams.orderHash); | ||
expect(preCanceled).to.be.bignumber.equal(ZERO); | ||
|
||
await subject(); | ||
|
||
const canceled = await core.orderCancels.callAsync(issuanceOrderParams.orderHash); | ||
expect(canceled).to.be.bignumber.equal(subjectQuantityToCancel); | ||
}); | ||
|
||
describe("when the quantity to cancel is not positive", async () => { | ||
beforeEach(async () => { | ||
subjectQuantityToCancel = ZERO; | ||
}); | ||
|
||
it("should revert", async () => { | ||
await expectRevertError(subject()); | ||
}); | ||
}); | ||
|
||
describe("when the transaction sender is not the maker", async () => { | ||
beforeEach(async () => { | ||
subjectCaller = takerAccount; | ||
}); | ||
|
||
it("should revert", async () => { | ||
await expectRevertError(subject()); | ||
}); | ||
}); | ||
|
||
describe("when the order has expired", async () => { | ||
beforeEach(async () => { | ||
issuanceOrderParams = await generateFillOrderParameters(setToken.address, signerAddress, signerAddress, componentAddresses[0], undefined, undefined, -1) | ||
}); | ||
|
||
it("should revert", async () => { | ||
await expectRevertError(subject()); | ||
}); | ||
}); | ||
|
||
describe("when invalid Set Token quantity in Issuance Order", async () => { | ||
beforeEach(async () => { | ||
issuanceOrderParams = await generateFillOrderParameters(setToken.address, signerAddress, signerAddress, componentAddresses[0], ZERO) | ||
}); | ||
|
||
it("should revert", async () => { | ||
await expectRevertError(subject()); | ||
}); | ||
}); | ||
|
||
describe("when invalid makerTokenAmount in Issuance Order", async () => { | ||
beforeEach(async () => { | ||
issuanceOrderParams = await generateFillOrderParameters(setToken.address, signerAddress, signerAddress, componentAddresses[0], undefined, ZERO) | ||
}); | ||
|
||
it("should revert", async () => { | ||
await expectRevertError(subject()); | ||
}); | ||
}); | ||
}); | ||
}); |
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.
Also check that the order hasn't been already cancelled?
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.
Yeah my original comment addresses that...it's gonna be in the next PR.