Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit 2bb5d90

Browse files
committed
Added test for basic issue implementation within IssuanceOrder.
1 parent ca647d4 commit 2bb5d90

File tree

4 files changed

+160
-76
lines changed

4 files changed

+160
-76
lines changed

contracts/core/Core.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { CoreAccounting } from "./extensions/CoreAccounting.sol";
2020
import { CoreFactory } from "./extensions/CoreFactory.sol";
2121
import { CoreInternal } from "./extensions/CoreInternal.sol";
2222
import { CoreIssuance } from "./extensions/CoreIssuance.sol";
23+
import { CoreIssuanceOrder } from "./extensions/CoreIssuanceOrder.sol";
24+
2325

2426

2527
/**
@@ -30,8 +32,9 @@ import { CoreIssuance } from "./extensions/CoreIssuance.sol";
3032
* creating Sets, as well as all collateral flows throughout the system.
3133
*/
3234
contract Core is
35+
CoreIssuanceOrder,
3336
CoreAccounting,
34-
CoreIssuance,
3537
CoreInternal,
36-
CoreFactory
38+
CoreFactory,
39+
CoreIssuance
3740
{}

contracts/core/extensions/CoreIssuanceOrder.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pragma solidity 0.4.24;
1818

1919

2020
import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol";
21+
import { ICoreIssuance } from "../interfaces/ICoreIssuance.sol";
2122
import { CoreModifiers } from "../lib/CoreSharedModifiers.sol";
2223

2324
/**
@@ -30,7 +31,8 @@ import { CoreModifiers } from "../lib/CoreSharedModifiers.sol";
3031
*/
3132

3233
contract CoreIssuanceOrder is
33-
CoreModifiers
34+
CoreModifiers,
35+
ICoreIssuance
3436
{
3537
using SafeMath for uint256;
3638

@@ -45,6 +47,6 @@ contract CoreIssuanceOrder is
4547
isNaturalUnitMultiple(_quantity, _setAddress)
4648
{
4749
//Issue Set
48-
//issueInternal(_maker, _setAddress, _quantity);
50+
issueInternal(_maker, _setAddress, _quantity);
4951
}
5052
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2018 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
pragma solidity 0.4.24;
18+
19+
/**
20+
* @title ICoreIssuance
21+
* @author Set Protocol
22+
*
23+
* The ICoreIssuance Contract defines all the functions exposed in the CoreIssuance
24+
* extension.
25+
*/
26+
27+
contract ICoreIssuance {
28+
29+
/**
30+
* Issue
31+
*
32+
* @param _setAddress Address of set to issue
33+
* @param _quantity Quantity of set to issue
34+
*/
35+
function issue(
36+
address _setAddress,
37+
uint _quantity
38+
)
39+
external;
40+
41+
/**
42+
* Function to convert Set Tokens into underlying components
43+
*
44+
* @param _setAddress The address of the Set token
45+
* @param _quantity The number of tokens to redeem
46+
*/
47+
function redeem(
48+
address _setAddress,
49+
uint _quantity
50+
)
51+
external;
52+
53+
/**
54+
* Issue internally. Can define who to issue to.
55+
*
56+
* @param _owner Address to issue set to
57+
* @param _setAddress Address of set to issue
58+
* @param _quantity Quantity of set to issue
59+
*/
60+
function issueInternal(
61+
address _owner,
62+
address _setAddress,
63+
uint _quantity
64+
)
65+
internal;
66+
}

test/core/extensions/coreIssuanceOrder.spec.ts

Lines changed: 85 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -52,75 +52,88 @@ import {
5252
assertLogEquivalence,
5353
} from "../../logs/logAssertions";
5454

55-
// contract("CoreIssuance", (accounts) => {
56-
// const [
57-
// ownerAccount
58-
// takerAccount,
59-
// makerAccount,
60-
// unauthorizedAccount,
61-
// ] = accounts;
62-
63-
// let core: CoreContract;
64-
// let transferProxy: TransferProxyContract;
65-
// let vault: VaultContract;
66-
// let setTokenFactory: SetTokenFactoryContract;
67-
68-
// const coreWrapper = new CoreWrapper(ownerAccount, ownerAccount);
69-
// const erc20Wrapper = new ERC20Wrapper(takerAccount);
70-
71-
// before(async () => {
72-
// ABIDecoder.addABI(Core.abi);
73-
// });
74-
75-
// after(async () => {
76-
// ABIDecoder.removeABI(Core.abi);
77-
// });
78-
79-
// beforeEach(async () => {
80-
// core = await coreWrapper.deployCoreAsync();
81-
// vault = await coreWrapper.deployVaultAsync();
82-
// transferProxy = await coreWrapper.deployTransferProxyAsync(vault.address);
83-
// setTokenFactory = await coreWrapper.deploySetTokenFactoryAsync();
84-
// await coreWrapper.setDefaultStateAndAuthorizationsAsync(core, vault, transferProxy, setTokenFactory);
85-
// });
86-
87-
// describe("#fillOrder", async () => {
88-
// let subjectCaller: Address;
89-
// let subjectQuantityToIssue: BigNumber;
90-
// let subjectSetToIssue: Address;
91-
92-
// const naturalUnit: BigNumber = ether(2);
93-
// let components: StandardTokenMockContract[] = [];
94-
// let componentUnits: BigNumber[];
95-
// let setToken: SetTokenContract;
96-
97-
// beforeEach(async () => {
98-
// components = await erc20Wrapper.deployTokensAsync(2, ownerAccount);
99-
// await erc20Wrapper.approveTransfersAsync(components, transferProxy.address);
100-
101-
// const componentAddresses = _.map(components, (token) => token.address);
102-
// componentUnits = _.map(components, () => ether(4)); // Multiple of naturalUnit
103-
// setToken = await coreWrapper.createSetTokenAsync(
104-
// core,
105-
// setTokenFactory.address,
106-
// componentAddresses,
107-
// componentUnits,
108-
// naturalUnit,
109-
// );
110-
111-
// subjectCaller = ownerAccount;
112-
// subjectQuantityToIssue = ether(2);
113-
// subjectSetToIssue = setToken.address;
114-
// });
115-
116-
// async function subject(): Promise<string> {
117-
// return core.fillOrder.sendTransactionAsync(
118-
// subjectSetToIssue,
119-
// subjectQuantityToIssue,
120-
// { from: ownerAccount },
121-
// );
122-
// }
123-
124-
// it()
125-
// });
126-
// });
55+
contract("CoreIssuance", (accounts) => {
56+
const [
57+
ownerAccount,
58+
takerAccount,
59+
makerAccount,
60+
unauthorizedAccount,
61+
] = accounts;
62+
63+
let core: CoreContract;
64+
let transferProxy: TransferProxyContract;
65+
let vault: VaultContract;
66+
let setTokenFactory: SetTokenFactoryContract;
67+
68+
const coreWrapper = new CoreWrapper(ownerAccount, ownerAccount);
69+
const erc20Wrapper = new ERC20Wrapper(ownerAccount);
70+
71+
before(async () => {
72+
ABIDecoder.addABI(Core.abi);
73+
});
74+
75+
after(async () => {
76+
ABIDecoder.removeABI(Core.abi);
77+
});
78+
79+
beforeEach(async () => {
80+
core = await coreWrapper.deployCoreAsync();
81+
vault = await coreWrapper.deployVaultAsync();
82+
transferProxy = await coreWrapper.deployTransferProxyAsync(vault.address);
83+
setTokenFactory = await coreWrapper.deploySetTokenFactoryAsync();
84+
await coreWrapper.setDefaultStateAndAuthorizationsAsync(core, vault, transferProxy, setTokenFactory);
85+
});
86+
87+
describe.only("#fillOrder", async () => {
88+
let subjectCaller: Address;
89+
let subjectQuantityToIssue: BigNumber;
90+
let subjectSetToIssue: Address;
91+
92+
const naturalUnit: BigNumber = ether(2);
93+
let components: StandardTokenMockContract[] = [];
94+
let componentUnits: BigNumber[];
95+
let setToken: SetTokenContract;
96+
97+
beforeEach(async () => {
98+
components = await erc20Wrapper.deployTokensAsync(2, makerAccount);
99+
await erc20Wrapper.approveTransfersAsync(components, transferProxy.address, makerAccount);
100+
101+
const componentAddresses = _.map(components, (token) => token.address);
102+
componentUnits = _.map(components, () => ether(4)); // Multiple of naturalUnit
103+
setToken = await coreWrapper.createSetTokenAsync(
104+
core,
105+
setTokenFactory.address,
106+
componentAddresses,
107+
componentUnits,
108+
naturalUnit,
109+
);
110+
111+
subjectCaller = takerAccount;
112+
subjectQuantityToIssue = ether(2);
113+
subjectSetToIssue = setToken.address;
114+
});
115+
116+
async function subject(): Promise<string> {
117+
return core.fillOrder.sendTransactionAsync(
118+
makerAccount,
119+
subjectSetToIssue,
120+
subjectQuantityToIssue,
121+
{ from: ownerAccount },
122+
);
123+
}
124+
125+
it("transfers the required tokens from the user", async () => {
126+
const component: StandardTokenMockContract = _.first(components);
127+
const unit: BigNumber = _.first(componentUnits);
128+
129+
const existingBalance = await component.balanceOf.callAsync(makerAccount);
130+
assertTokenBalance(component, DEPLOYED_TOKEN_QUANTITY, makerAccount);
131+
132+
await subject();
133+
134+
const newBalance = await component.balanceOf.callAsync(makerAccount);
135+
const expectedNewBalance = existingBalance.sub(subjectQuantityToIssue.div(naturalUnit).mul(unit));
136+
expect(newBalance).to.be.bignumber.equal(expectedNewBalance);
137+
});
138+
});
139+
});

0 commit comments

Comments
 (0)