mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
refactor TestContractHandler.getAccounts()
This commit is contained in:
parent
f0a008ce89
commit
1e12ddd630
@ -46,8 +46,6 @@ const deployContract = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TestContractHandler {
|
export class TestContractHandler {
|
||||||
public accounts: string[]
|
|
||||||
|
|
||||||
public ERC721Factory: Contract
|
public ERC721Factory: Contract
|
||||||
public ERC20Template: Contract
|
public ERC20Template: Contract
|
||||||
public ERC721Template: Contract
|
public ERC721Template: Contract
|
||||||
@ -91,11 +89,6 @@ export class TestContractHandler {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAccounts(): Promise<string[]> {
|
|
||||||
this.accounts = await this.web3.eth.getAccounts()
|
|
||||||
return this.accounts
|
|
||||||
}
|
|
||||||
|
|
||||||
public async deployContracts(owner: string) {
|
public async deployContracts(owner: string) {
|
||||||
const addresses = getAddresses()
|
const addresses = getAddresses()
|
||||||
|
|
||||||
|
@ -23,15 +23,17 @@ describe('Nft Factory test', () => {
|
|||||||
let dtAddress2: string
|
let dtAddress2: string
|
||||||
let nftAddress: string
|
let nftAddress: string
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
factoryOwner = accounts[0]
|
||||||
|
nftOwner = accounts[1]
|
||||||
|
user1 = accounts[2]
|
||||||
|
user2 = accounts[3]
|
||||||
|
user3 = accounts[4]
|
||||||
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = new TestContractHandler(web3)
|
||||||
await contracts.getAccounts()
|
|
||||||
factoryOwner = contracts.accounts[0]
|
|
||||||
nftOwner = contracts.accounts[1]
|
|
||||||
user1 = contracts.accounts[2]
|
|
||||||
user2 = contracts.accounts[3]
|
|
||||||
user3 = contracts.accounts[4]
|
|
||||||
|
|
||||||
await contracts.deployContracts(factoryOwner)
|
await contracts.deployContracts(factoryOwner)
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
@ -40,7 +42,7 @@ describe('Nft Factory test', () => {
|
|||||||
)
|
)
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.approve(contracts.factory721Address, web3.utils.toWei('10000'))
|
.approve(contracts.factory721Address, web3.utils.toWei('10000'))
|
||||||
.send({ from: contracts.accounts[0] })
|
.send({ from: factoryOwner })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should initiate NFTFactory instance', async () => {
|
it('should initiate NFTFactory instance', async () => {
|
||||||
@ -49,7 +51,7 @@ describe('Nft Factory test', () => {
|
|||||||
|
|
||||||
it('#getOwner - should return actual owner', async () => {
|
it('#getOwner - should return actual owner', async () => {
|
||||||
const owner = await nftFactory.getOwner()
|
const owner = await nftFactory.getOwner()
|
||||||
assert(owner === contracts.accounts[0])
|
assert(owner === factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getNFTTemplate - should return NFT template struct', async () => {
|
it('#getNFTTemplate - should return NFT template struct', async () => {
|
||||||
@ -74,7 +76,7 @@ describe('Nft Factory test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: user2,
|
mpFeeAddress: user2,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
@ -85,7 +87,7 @@ describe('Nft Factory test', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftWithErc20(
|
const txReceipt = await nftFactory.createNftWithErc20(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams
|
ercParams
|
||||||
)
|
)
|
||||||
@ -124,8 +126,8 @@ describe('Nft Factory test', () => {
|
|||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
baseTokenSender: contracts.factory721Address,
|
baseTokenSender: contracts.factory721Address,
|
||||||
publisherAddress: contracts.accounts[0],
|
publisherAddress: factoryOwner,
|
||||||
marketFeeCollector: contracts.accounts[0],
|
marketFeeCollector: factoryOwner,
|
||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -137,7 +139,7 @@ describe('Nft Factory test', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
poolParams
|
poolParams
|
||||||
@ -160,7 +162,7 @@ describe('Nft Factory test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: user2,
|
mpFeeAddress: user2,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
@ -173,18 +175,18 @@ describe('Nft Factory test', () => {
|
|||||||
const freParams: FreCreationParams = {
|
const freParams: FreCreationParams = {
|
||||||
fixedRateAddress: contracts.fixedRateAddress,
|
fixedRateAddress: contracts.fixedRateAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
owner: contracts.accounts[0],
|
owner: factoryOwner,
|
||||||
marketFeeCollector: contracts.accounts[0],
|
marketFeeCollector: factoryOwner,
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
datatokenDecimals: 18,
|
datatokenDecimals: 18,
|
||||||
fixedRate: '1',
|
fixedRate: '1',
|
||||||
marketFee: '0.001',
|
marketFee: '0.001',
|
||||||
allowedConsumer: contracts.accounts[0],
|
allowedConsumer: factoryOwner,
|
||||||
withMint: false
|
withMint: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithFixedRate(
|
const txReceipt = await nftFactory.createNftErc20WithFixedRate(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
freParams
|
freParams
|
||||||
@ -210,7 +212,7 @@ describe('Nft Factory test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: user2,
|
mpFeeAddress: user2,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
@ -229,7 +231,7 @@ describe('Nft Factory test', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithDispenser(
|
const txReceipt = await nftFactory.createNftErc20WithDispenser(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
@ -257,7 +259,7 @@ describe('Nft Factory test', () => {
|
|||||||
expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
|
|
||||||
// dt owner mint dtAmount to user2
|
// dt owner mint dtAmount to user2
|
||||||
await dtContract.methods.mint(user2, dtAmount).send({ from: contracts.accounts[0] })
|
await dtContract.methods.mint(user2, dtAmount).send({ from: factoryOwner })
|
||||||
|
|
||||||
// user2 approves NFTFactory to move his dtAmount
|
// user2 approves NFTFactory to move his dtAmount
|
||||||
await dtContract.methods
|
await dtContract.methods
|
||||||
@ -269,7 +271,7 @@ describe('Nft Factory test', () => {
|
|||||||
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
|
|
||||||
// dt owner mint dtAmount to user2
|
// dt owner mint dtAmount to user2
|
||||||
await dtContract2.methods.mint(user2, dtAmount).send({ from: contracts.accounts[0] })
|
await dtContract2.methods.mint(user2, dtAmount).send({ from: factoryOwner })
|
||||||
// user2 approves NFTFactory to move his dtAmount
|
// user2 approves NFTFactory to move his dtAmount
|
||||||
await dtContract2.methods
|
await dtContract2.methods
|
||||||
.approve(contracts.factory721Address, dtAmount)
|
.approve(contracts.factory721Address, dtAmount)
|
||||||
|
@ -22,15 +22,17 @@ describe('Router unit test', () => {
|
|||||||
let dtAddress2: string
|
let dtAddress2: string
|
||||||
let nftAddress: string
|
let nftAddress: string
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
factoryOwner = accounts[0]
|
||||||
|
nftOwner = accounts[1]
|
||||||
|
user1 = accounts[2]
|
||||||
|
user2 = accounts[3]
|
||||||
|
user3 = accounts[4]
|
||||||
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = new TestContractHandler(web3)
|
||||||
await contracts.getAccounts()
|
|
||||||
factoryOwner = contracts.accounts[0]
|
|
||||||
nftOwner = contracts.accounts[1]
|
|
||||||
user1 = contracts.accounts[2]
|
|
||||||
user2 = contracts.accounts[3]
|
|
||||||
user3 = contracts.accounts[4]
|
|
||||||
|
|
||||||
await contracts.deployContracts(factoryOwner)
|
await contracts.deployContracts(factoryOwner)
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
@ -39,7 +41,7 @@ describe('Router unit test', () => {
|
|||||||
)
|
)
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.approve(contracts.factory721Address, web3.utils.toWei('10000'))
|
.approve(contracts.factory721Address, web3.utils.toWei('10000'))
|
||||||
.send({ from: contracts.accounts[0] })
|
.send({ from: factoryOwner })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should initiate Router instance', async () => {
|
it('should initiate Router instance', async () => {
|
||||||
@ -48,7 +50,7 @@ describe('Router unit test', () => {
|
|||||||
|
|
||||||
it('#getOwner - should return actual owner', async () => {
|
it('#getOwner - should return actual owner', async () => {
|
||||||
const owner = await router.getOwner()
|
const owner = await router.getOwner()
|
||||||
assert(owner === contracts.accounts[0])
|
assert(owner === factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getNFTFactory - should return NFT Factory address', async () => {
|
it('#getNFTFactory - should return NFT Factory address', async () => {
|
||||||
@ -82,7 +84,7 @@ describe('Router unit test', () => {
|
|||||||
|
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.transfer(user2, web3.utils.toWei('2'))
|
.transfer(user2, web3.utils.toWei('2'))
|
||||||
.send({ from: contracts.accounts[0] })
|
.send({ from: factoryOwner })
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.approve(contracts.routerAddress, web3.utils.toWei('2'))
|
.approve(contracts.routerAddress, web3.utils.toWei('2'))
|
||||||
.send({ from: user2 })
|
.send({ from: user2 })
|
||||||
@ -98,9 +100,9 @@ describe('Router unit test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: contracts.accounts[0],
|
mpFeeAddress: factoryOwner,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
@ -112,8 +114,8 @@ describe('Router unit test', () => {
|
|||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
baseTokenSender: contracts.factory721Address,
|
baseTokenSender: contracts.factory721Address,
|
||||||
publisherAddress: contracts.accounts[0],
|
publisherAddress: factoryOwner,
|
||||||
marketFeeCollector: contracts.accounts[0],
|
marketFeeCollector: factoryOwner,
|
||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -131,7 +133,7 @@ describe('Router unit test', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
poolParams
|
poolParams
|
||||||
@ -151,9 +153,9 @@ describe('Router unit test', () => {
|
|||||||
|
|
||||||
const ercParams2: Erc20CreateParams = {
|
const ercParams2: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: contracts.accounts[0],
|
mpFeeAddress: factoryOwner,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
@ -165,8 +167,8 @@ describe('Router unit test', () => {
|
|||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
baseTokenSender: contracts.factory721Address,
|
baseTokenSender: contracts.factory721Address,
|
||||||
publisherAddress: contracts.accounts[0],
|
publisherAddress: factoryOwner,
|
||||||
marketFeeCollector: contracts.accounts[0],
|
marketFeeCollector: factoryOwner,
|
||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -178,7 +180,7 @@ describe('Router unit test', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt2 = await nftFactory.createNftErc20WithPool(
|
const txReceipt2 = await nftFactory.createNftErc20WithPool(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData2,
|
nftData2,
|
||||||
ercParams2,
|
ercParams2,
|
||||||
poolParams2
|
poolParams2
|
||||||
@ -217,7 +219,7 @@ describe('Router unit test', () => {
|
|||||||
amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT
|
amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT
|
||||||
maxPrice: web3.utils.toWei('10'), // max price (only for pools),
|
maxPrice: web3.utils.toWei('10'), // max price (only for pools),
|
||||||
swapMarketFee: web3.utils.toWei('0.1'),
|
swapMarketFee: web3.utils.toWei('0.1'),
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
|
|
||||||
const operations2: Operation = {
|
const operations2: Operation = {
|
||||||
@ -230,7 +232,7 @@ describe('Router unit test', () => {
|
|||||||
amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT
|
amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT
|
||||||
maxPrice: web3.utils.toWei('10'), // max price (only for pools)
|
maxPrice: web3.utils.toWei('10'), // max price (only for pools)
|
||||||
swapMarketFee: web3.utils.toWei('0.1'),
|
swapMarketFee: web3.utils.toWei('0.1'),
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
|
|
||||||
await router.buyDTBatch(user2, [operations1, operations2])
|
await router.buyDTBatch(user2, [operations1, operations2])
|
||||||
|
@ -40,15 +40,17 @@ describe('Pool unit test', () => {
|
|||||||
let daiContract: Contract
|
let daiContract: Contract
|
||||||
let usdcContract: Contract
|
let usdcContract: Contract
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
factoryOwner = accounts[0]
|
||||||
|
nftOwner = accounts[1]
|
||||||
|
user1 = accounts[2]
|
||||||
|
user2 = accounts[3]
|
||||||
|
user3 = accounts[4]
|
||||||
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = new TestContractHandler(web3)
|
||||||
await contracts.getAccounts()
|
|
||||||
factoryOwner = contracts.accounts[0]
|
|
||||||
nftOwner = contracts.accounts[1]
|
|
||||||
user1 = contracts.accounts[2]
|
|
||||||
user2 = contracts.accounts[3]
|
|
||||||
user3 = contracts.accounts[4]
|
|
||||||
|
|
||||||
await contracts.deployContracts(factoryOwner)
|
await contracts.deployContracts(factoryOwner)
|
||||||
|
|
||||||
// initialize Pool instance
|
// initialize Pool instance
|
||||||
@ -66,14 +68,14 @@ describe('Pool unit test', () => {
|
|||||||
)
|
)
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
contracts.factory721Address,
|
contracts.factory721Address,
|
||||||
'2000'
|
'2000'
|
||||||
)
|
)
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
contracts.factory721Address,
|
contracts.factory721Address,
|
||||||
'10000'
|
'10000'
|
||||||
@ -82,7 +84,7 @@ describe('Pool unit test', () => {
|
|||||||
let allowCheck = await allowance(
|
let allowCheck = await allowance(
|
||||||
web3,
|
web3,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.factory721Address
|
contracts.factory721Address
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,7 +92,7 @@ describe('Pool unit test', () => {
|
|||||||
allowCheck = await allowance(
|
allowCheck = await allowance(
|
||||||
web3,
|
web3,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.factory721Address
|
contracts.factory721Address
|
||||||
)
|
)
|
||||||
assert(parseInt(allowCheck) >= 10000)
|
assert(parseInt(allowCheck) >= 10000)
|
||||||
@ -111,9 +113,9 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: contracts.accounts[0],
|
mpFeeAddress: factoryOwner,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
@ -127,8 +129,8 @@ describe('Pool unit test', () => {
|
|||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
baseTokenSender: contracts.factory721Address,
|
baseTokenSender: contracts.factory721Address,
|
||||||
publisherAddress: contracts.accounts[0],
|
publisherAddress: factoryOwner,
|
||||||
marketFeeCollector: contracts.accounts[0],
|
marketFeeCollector: factoryOwner,
|
||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -146,7 +148,7 @@ describe('Pool unit test', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
poolParams
|
poolParams
|
||||||
@ -172,11 +174,8 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
it('#getPoolSharesTotalSupply - should return totalSupply of LPT', async () => {
|
it('#getPoolSharesTotalSupply - should return totalSupply of LPT', async () => {
|
||||||
// dt owner which added liquidity has half of pool shares (the rest is in the sidestaking contracta)
|
// dt owner which added liquidity has half of pool shares (the rest is in the sidestaking contracta)
|
||||||
const dtOwnerLPTBalance = await pool.sharesBalance(
|
const dtOwnerLPTBalance = await pool.sharesBalance(factoryOwner, poolAddress)
|
||||||
contracts.accounts[0],
|
expect(await pool.sharesBalance(factoryOwner, poolAddress)).to.equal(
|
||||||
poolAddress
|
|
||||||
)
|
|
||||||
expect(await pool.sharesBalance(contracts.accounts[0], poolAddress)).to.equal(
|
|
||||||
await pool.sharesBalance(contracts.sideStakingAddress, poolAddress)
|
await pool.sharesBalance(contracts.sideStakingAddress, poolAddress)
|
||||||
)
|
)
|
||||||
// total supply is twice the dtOwner balance
|
// total supply is twice the dtOwner balance
|
||||||
@ -244,7 +243,7 @@ describe('Pool unit test', () => {
|
|||||||
it('#swapExactAmountIn - should swap', async () => {
|
it('#swapExactAmountIn - should swap', async () => {
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.transfer(user2, web3.utils.toWei('1000'))
|
.transfer(user2, web3.utils.toWei('1000'))
|
||||||
.send({ from: contracts.accounts[0] })
|
.send({ from: factoryOwner })
|
||||||
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
|
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
|
||||||
web3.utils.toWei('1000')
|
web3.utils.toWei('1000')
|
||||||
)
|
)
|
||||||
@ -254,7 +253,7 @@ describe('Pool unit test', () => {
|
|||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
tokenAmountIn: '10',
|
tokenAmountIn: '10',
|
||||||
@ -280,7 +279,7 @@ describe('Pool unit test', () => {
|
|||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
maxAmountIn: '100',
|
maxAmountIn: '100',
|
||||||
@ -474,12 +473,12 @@ describe('Pool unit test', () => {
|
|||||||
'0.1'
|
'0.1'
|
||||||
)
|
)
|
||||||
|
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// factoryOwner is the marketFeeCollector
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
||||||
// user3 has no DAI (we are going to send DAI fee to him)
|
// user3 has no DAI (we are going to send DAI fee to him)
|
||||||
assert((await daiContract.methods.balanceOf(user3).call()) === '0')
|
assert((await daiContract.methods.balanceOf(user3).call()) === '0')
|
||||||
// only marketFeeCollector can call this, set user3 as receiver
|
// only marketFeeCollector can call this, set user3 as receiver
|
||||||
await pool.collectMarketFee(contracts.accounts[0], poolAddress)
|
await pool.collectMarketFee(factoryOwner, poolAddress)
|
||||||
// DAI fees have been collected
|
// DAI fees have been collected
|
||||||
assert((await pool.getMarketFees(poolAddress, contracts.daiAddress)) === '0')
|
assert((await pool.getMarketFees(poolAddress, contracts.daiAddress)) === '0')
|
||||||
|
|
||||||
@ -495,8 +494,8 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getMarketFeeCollector- should get market fees for each token', async () => {
|
it('#getMarketFeeCollector- should get market fees for each token', async () => {
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// factoryOwner is the marketFeeCollector
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getOPCCollector- should get market fees for each token', async () => {
|
it('#getOPCCollector- should get market fees for each token', async () => {
|
||||||
@ -518,7 +517,7 @@ describe('Pool unit test', () => {
|
|||||||
'0'
|
'0'
|
||||||
)
|
)
|
||||||
// anyone can call callectOPF
|
// anyone can call callectOPF
|
||||||
await pool.collectOPC(contracts.accounts[0], poolAddress)
|
await pool.collectOPC(factoryOwner, poolAddress)
|
||||||
// DAI fees have been collected
|
// DAI fees have been collected
|
||||||
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) === '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) === '0')
|
||||||
// OPF collector got DAI
|
// OPF collector got DAI
|
||||||
@ -537,11 +536,11 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// factoryOwner is the marketFeeCollector
|
||||||
|
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
||||||
await pool.updatePublishMarketFee(
|
await pool.updatePublishMarketFee(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
user3,
|
user3,
|
||||||
await pool.getMarketFee(poolAddress)
|
await pool.getMarketFee(poolAddress)
|
||||||
@ -563,9 +562,9 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: contracts.accounts[0],
|
mpFeeAddress: factoryOwner,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
@ -577,8 +576,8 @@ describe('Pool unit test', () => {
|
|||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.usdcAddress,
|
baseTokenAddress: contracts.usdcAddress,
|
||||||
baseTokenSender: contracts.factory721Address,
|
baseTokenSender: contracts.factory721Address,
|
||||||
publisherAddress: contracts.accounts[0],
|
publisherAddress: factoryOwner,
|
||||||
marketFeeCollector: contracts.accounts[0],
|
marketFeeCollector: factoryOwner,
|
||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: await usdcContract.methods.decimals().call(),
|
baseTokenDecimals: await usdcContract.methods.decimals().call(),
|
||||||
@ -600,7 +599,7 @@ describe('Pool unit test', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
poolParams
|
poolParams
|
||||||
@ -697,11 +696,8 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
it('#getPoolSharesTotalSupply - should return totalSupply of LPT', async () => {
|
it('#getPoolSharesTotalSupply - should return totalSupply of LPT', async () => {
|
||||||
// dt owner which added liquidity has half of pool shares (the rest is in the sidestaking contracta)
|
// dt owner which added liquidity has half of pool shares (the rest is in the sidestaking contracta)
|
||||||
const dtOwnerLPTBalance = await pool.sharesBalance(
|
const dtOwnerLPTBalance = await pool.sharesBalance(factoryOwner, poolAddress)
|
||||||
contracts.accounts[0],
|
expect(await pool.sharesBalance(factoryOwner, poolAddress)).to.equal(
|
||||||
poolAddress
|
|
||||||
)
|
|
||||||
expect(await pool.sharesBalance(contracts.accounts[0], poolAddress)).to.equal(
|
|
||||||
await pool.sharesBalance(contracts.sideStakingAddress, poolAddress)
|
await pool.sharesBalance(contracts.sideStakingAddress, poolAddress)
|
||||||
)
|
)
|
||||||
// total supply is twice the dtOwner balance
|
// total supply is twice the dtOwner balance
|
||||||
@ -770,7 +766,7 @@ describe('Pool unit test', () => {
|
|||||||
const transferAmount = await amountToUnits(web3, contracts.usdcAddress, '1000') // 1000 USDC
|
const transferAmount = await amountToUnits(web3, contracts.usdcAddress, '1000') // 1000 USDC
|
||||||
await usdcContract.methods
|
await usdcContract.methods
|
||||||
.transfer(user2, transferAmount)
|
.transfer(user2, transferAmount)
|
||||||
.send({ from: contracts.accounts[0] })
|
.send({ from: factoryOwner })
|
||||||
expect(await usdcContract.methods.balanceOf(user2).call()).to.equal(
|
expect(await usdcContract.methods.balanceOf(user2).call()).to.equal(
|
||||||
transferAmount.toString()
|
transferAmount.toString()
|
||||||
)
|
)
|
||||||
@ -780,7 +776,7 @@ describe('Pool unit test', () => {
|
|||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
tokenAmountIn: '10',
|
tokenAmountIn: '10',
|
||||||
@ -806,7 +802,7 @@ describe('Pool unit test', () => {
|
|||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
maxAmountIn: '100',
|
maxAmountIn: '100',
|
||||||
@ -987,12 +983,12 @@ describe('Pool unit test', () => {
|
|||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
'0.1'
|
'0.1'
|
||||||
)
|
)
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// factoryOwner is the marketFeeCollector
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
||||||
// user3 has no USDC (we are going to send USDC fee to him)
|
// user3 has no USDC (we are going to send USDC fee to him)
|
||||||
assert((await usdcContract.methods.balanceOf(user3).call()) === '0')
|
assert((await usdcContract.methods.balanceOf(user3).call()) === '0')
|
||||||
// only marketFeeCollector can call this, set user3 as receiver
|
// only marketFeeCollector can call this, set user3 as receiver
|
||||||
await pool.collectMarketFee(contracts.accounts[0], poolAddress)
|
await pool.collectMarketFee(factoryOwner, poolAddress)
|
||||||
// USDC fees have been collected
|
// USDC fees have been collected
|
||||||
assert((await pool.getMarketFees(poolAddress, contracts.usdcAddress)) === '0')
|
assert((await pool.getMarketFees(poolAddress, contracts.usdcAddress)) === '0')
|
||||||
|
|
||||||
@ -1008,8 +1004,8 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getMarketFeeCollector- should get market fees for each token', async () => {
|
it('#getMarketFeeCollector- should get market fees for each token', async () => {
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// factoryOwner is the marketFeeCollector
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getOPCCollector- should get market fees for each token', async () => {
|
it('#getOPCCollector- should get market fees for each token', async () => {
|
||||||
@ -1041,7 +1037,7 @@ describe('Pool unit test', () => {
|
|||||||
'0'
|
'0'
|
||||||
)
|
)
|
||||||
// anyone can call callectOPF
|
// anyone can call callectOPF
|
||||||
await pool.collectOPC(contracts.accounts[0], poolAddress)
|
await pool.collectOPC(factoryOwner, poolAddress)
|
||||||
// USDC fees have been collected
|
// USDC fees have been collected
|
||||||
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) === '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) === '0')
|
||||||
// OPF collector got USDC
|
// OPF collector got USDC
|
||||||
@ -1060,11 +1056,11 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// factoryOwner is the marketFeeCollector
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
||||||
|
|
||||||
await pool.updatePublishMarketFee(
|
await pool.updatePublishMarketFee(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
user3,
|
user3,
|
||||||
await pool.getMarketFee(poolAddress)
|
await pool.getMarketFee(poolAddress)
|
||||||
|
@ -27,15 +27,17 @@ describe('Dispenser flow', () => {
|
|||||||
let nftAddress: string
|
let nftAddress: string
|
||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
factoryOwner = accounts[0]
|
||||||
|
nftOwner = accounts[1]
|
||||||
|
user1 = accounts[2]
|
||||||
|
user2 = accounts[3]
|
||||||
|
user3 = accounts[4]
|
||||||
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = new TestContractHandler(web3)
|
||||||
await contracts.getAccounts()
|
|
||||||
factoryOwner = contracts.accounts[0]
|
|
||||||
nftOwner = contracts.accounts[1]
|
|
||||||
user1 = contracts.accounts[2]
|
|
||||||
user2 = contracts.accounts[3]
|
|
||||||
user3 = contracts.accounts[4]
|
|
||||||
|
|
||||||
await contracts.deployContracts(factoryOwner)
|
await contracts.deployContracts(factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -60,7 +62,7 @@ describe('Dispenser flow', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: user2,
|
mpFeeAddress: user2,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
@ -71,7 +73,7 @@ describe('Dispenser flow', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftWithErc20(
|
const txReceipt = await nftFactory.createNftWithErc20(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams
|
ercParams
|
||||||
)
|
)
|
||||||
@ -85,7 +87,7 @@ describe('Dispenser flow', () => {
|
|||||||
|
|
||||||
it('Make user2 minter', async () => {
|
it('Make user2 minter', async () => {
|
||||||
datatoken = new Datatoken(web3, ERC20Template.abi as AbiItem[])
|
datatoken = new Datatoken(web3, ERC20Template.abi as AbiItem[])
|
||||||
await datatoken.addMinter(dtAddress, contracts.accounts[0], user2)
|
await datatoken.addMinter(dtAddress, factoryOwner, user2)
|
||||||
assert((await datatoken.getDTPermissions(dtAddress, user2)).minter === true)
|
assert((await datatoken.getDTPermissions(dtAddress, user2)).minter === true)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -97,7 +99,7 @@ describe('Dispenser flow', () => {
|
|||||||
}
|
}
|
||||||
const tx = await datatoken.createDispenser(
|
const tx = await datatoken.createDispenser(
|
||||||
dtAddress,
|
dtAddress,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.dispenserAddress,
|
contracts.dispenserAddress,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
)
|
)
|
||||||
@ -105,42 +107,33 @@ describe('Dispenser flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('Activate dispenser', async () => {
|
it('Activate dispenser', async () => {
|
||||||
const tx = await DispenserClass.activate(dtAddress, '1', '1', contracts.accounts[0])
|
const tx = await DispenserClass.activate(dtAddress, '1', '1', factoryOwner)
|
||||||
assert(tx, 'Cannot activate dispenser')
|
assert(tx, 'Cannot activate dispenser')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('user2 gets the dispenser status', async () => {
|
it('user2 gets the dispenser status', async () => {
|
||||||
const status = await DispenserClass.status(dtAddress)
|
const status = await DispenserClass.status(dtAddress)
|
||||||
assert(status.active === true, 'Dispenser not active')
|
assert(status.active === true, 'Dispenser not active')
|
||||||
assert(status.owner === contracts.accounts[0], 'Dispenser owner is not alice')
|
assert(status.owner === factoryOwner, 'Dispenser owner is not alice')
|
||||||
assert(status.isMinter === true, 'Dispenser is not a minter')
|
assert(status.isMinter === true, 'Dispenser is not a minter')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('user2 deactivates the dispenser', async () => {
|
it('user2 deactivates the dispenser', async () => {
|
||||||
const tx = await DispenserClass.deactivate(dtAddress, contracts.accounts[0])
|
const tx = await DispenserClass.deactivate(dtAddress, factoryOwner)
|
||||||
assert(tx, 'Cannot deactivate dispenser')
|
assert(tx, 'Cannot deactivate dispenser')
|
||||||
const status = await DispenserClass.status(dtAddress)
|
const status = await DispenserClass.status(dtAddress)
|
||||||
assert(status.active === false, 'Dispenser is still active')
|
assert(status.active === false, 'Dispenser is still active')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('user2 sets user3 as an AllowedSwapper for the dispenser', async () => {
|
it('user2 sets user3 as an AllowedSwapper for the dispenser', async () => {
|
||||||
const tx = await DispenserClass.setAllowedSwapper(
|
const tx = await DispenserClass.setAllowedSwapper(dtAddress, factoryOwner, user3)
|
||||||
dtAddress,
|
|
||||||
contracts.accounts[0],
|
|
||||||
user3
|
|
||||||
)
|
|
||||||
assert(tx, 'Cannot set Allowed Swapper')
|
assert(tx, 'Cannot set Allowed Swapper')
|
||||||
const status = await DispenserClass.status(dtAddress)
|
const status = await DispenserClass.status(dtAddress)
|
||||||
assert(status.allowedSwapper === user3, 'user3 is Allowed Swapper')
|
assert(status.allowedSwapper === user3, 'user3 is Allowed Swapper')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('User3 requests datatokens', async () => {
|
it('User3 requests datatokens', async () => {
|
||||||
const activate = await DispenserClass.activate(
|
const activate = await DispenserClass.activate(dtAddress, '10', '10', factoryOwner)
|
||||||
dtAddress,
|
|
||||||
'10',
|
|
||||||
'10',
|
|
||||||
contracts.accounts[0]
|
|
||||||
)
|
|
||||||
const check = await DispenserClass.isDispensable(dtAddress, datatoken, user3, '1')
|
const check = await DispenserClass.isDispensable(dtAddress, datatoken, user3, '1')
|
||||||
assert(check === true, 'isDispensable should return true')
|
assert(check === true, 'isDispensable should return true')
|
||||||
const tx = await DispenserClass.dispense(dtAddress, user3, '1', user3)
|
const tx = await DispenserClass.dispense(dtAddress, user3, '1', user3)
|
||||||
@ -153,7 +146,7 @@ describe('Dispenser flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('user2 withdraws all datatokens', async () => {
|
it('user2 withdraws all datatokens', async () => {
|
||||||
const tx = await DispenserClass.ownerWithdraw(dtAddress, contracts.accounts[0])
|
const tx = await DispenserClass.ownerWithdraw(dtAddress, factoryOwner)
|
||||||
assert(tx, 'user2 failed to withdraw all her tokens')
|
assert(tx, 'user2 failed to withdraw all her tokens')
|
||||||
const status = await DispenserClass.status(dtAddress)
|
const status = await DispenserClass.status(dtAddress)
|
||||||
assert(status.balance === '0', 'Balance > 0')
|
assert(status.balance === '0', 'Balance > 0')
|
||||||
|
@ -31,17 +31,20 @@ describe('Fixed Rate unit test', () => {
|
|||||||
let usdcContract: Contract
|
let usdcContract: Contract
|
||||||
const vestedBlocks = 2500000
|
const vestedBlocks = 2500000
|
||||||
const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'
|
const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
factoryOwner = accounts[0]
|
||||||
|
nftOwner = accounts[1]
|
||||||
|
user1 = accounts[2]
|
||||||
|
user2 = accounts[3]
|
||||||
|
user3 = accounts[4]
|
||||||
|
user4 = accounts[5]
|
||||||
|
exchangeOwner = accounts[0]
|
||||||
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = new TestContractHandler(web3)
|
||||||
await contracts.getAccounts()
|
|
||||||
factoryOwner = contracts.accounts[0]
|
|
||||||
nftOwner = contracts.accounts[1]
|
|
||||||
user1 = contracts.accounts[2]
|
|
||||||
user2 = contracts.accounts[3]
|
|
||||||
user3 = contracts.accounts[4]
|
|
||||||
user4 = contracts.accounts[5]
|
|
||||||
exchangeOwner = contracts.accounts[0]
|
|
||||||
|
|
||||||
await contracts.deployContracts(factoryOwner)
|
await contracts.deployContracts(factoryOwner)
|
||||||
|
|
||||||
// initialize fixed rate
|
// initialize fixed rate
|
||||||
@ -74,9 +77,9 @@ describe('Fixed Rate unit test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: contracts.accounts[0],
|
mpFeeAddress: factoryOwner,
|
||||||
feeToken: ADDRESS_ZERO,
|
feeToken: ADDRESS_ZERO,
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
@ -389,9 +392,9 @@ describe('Fixed Rate unit test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: contracts.accounts[0],
|
mpFeeAddress: factoryOwner,
|
||||||
feeToken: ADDRESS_ZERO,
|
feeToken: ADDRESS_ZERO,
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
|
@ -44,14 +44,17 @@ describe('SideStaking unit test', () => {
|
|||||||
let usdcContract: Contract
|
let usdcContract: Contract
|
||||||
const vestedBlocks = 2500000
|
const vestedBlocks = 2500000
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
factoryOwner = accounts[0]
|
||||||
|
nftOwner = accounts[1]
|
||||||
|
user1 = accounts[2]
|
||||||
|
user2 = accounts[3]
|
||||||
|
user3 = accounts[4]
|
||||||
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(web3)
|
contracts = new TestContractHandler(web3)
|
||||||
await contracts.getAccounts()
|
|
||||||
factoryOwner = contracts.accounts[0]
|
|
||||||
nftOwner = contracts.accounts[1]
|
|
||||||
user1 = contracts.accounts[2]
|
|
||||||
user2 = contracts.accounts[3]
|
|
||||||
user3 = contracts.accounts[4]
|
|
||||||
sideStakingAddress = contracts.sideStakingAddress
|
sideStakingAddress = contracts.sideStakingAddress
|
||||||
await contracts.deployContracts(factoryOwner)
|
await contracts.deployContracts(factoryOwner)
|
||||||
|
|
||||||
@ -73,14 +76,14 @@ describe('SideStaking unit test', () => {
|
|||||||
)
|
)
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
contracts.factory721Address,
|
contracts.factory721Address,
|
||||||
'2000'
|
'2000'
|
||||||
)
|
)
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
contracts.factory721Address,
|
contracts.factory721Address,
|
||||||
'10000'
|
'10000'
|
||||||
@ -89,14 +92,14 @@ describe('SideStaking unit test', () => {
|
|||||||
let allowCheck = await allowance(
|
let allowCheck = await allowance(
|
||||||
web3,
|
web3,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.factory721Address
|
contracts.factory721Address
|
||||||
)
|
)
|
||||||
assert(parseInt(allowCheck) >= 2000)
|
assert(parseInt(allowCheck) >= 2000)
|
||||||
allowCheck = await allowance(
|
allowCheck = await allowance(
|
||||||
web3,
|
web3,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
contracts.factory721Address
|
contracts.factory721Address
|
||||||
)
|
)
|
||||||
assert(parseInt(allowCheck) >= 10000)
|
assert(parseInt(allowCheck) >= 10000)
|
||||||
@ -124,9 +127,9 @@ describe('SideStaking unit test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: contracts.accounts[0],
|
mpFeeAddress: factoryOwner,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
@ -138,8 +141,8 @@ describe('SideStaking unit test', () => {
|
|||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
baseTokenSender: contracts.factory721Address,
|
baseTokenSender: contracts.factory721Address,
|
||||||
publisherAddress: contracts.accounts[0],
|
publisherAddress: factoryOwner,
|
||||||
marketFeeCollector: contracts.accounts[0],
|
marketFeeCollector: factoryOwner,
|
||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
@ -151,7 +154,7 @@ describe('SideStaking unit test', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
poolParams
|
poolParams
|
||||||
@ -202,7 +205,7 @@ describe('SideStaking unit test', () => {
|
|||||||
it('#getPublisherAddress - should get publisher address', async () => {
|
it('#getPublisherAddress - should get publisher address', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getPublisherAddress(sideStakingAddress, erc20Token)
|
await sideStaking.getPublisherAddress(sideStakingAddress, erc20Token)
|
||||||
).to.equal(contracts.accounts[0])
|
).to.equal(factoryOwner)
|
||||||
})
|
})
|
||||||
it('#getBaseTokenBalance ', async () => {
|
it('#getBaseTokenBalance ', async () => {
|
||||||
expect(
|
expect(
|
||||||
@ -238,12 +241,10 @@ describe('SideStaking unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getVesting ', async () => {
|
it('#getVesting ', async () => {
|
||||||
expect(
|
expect(await erc20Contract.methods.balanceOf(factoryOwner).call()).to.equal('0')
|
||||||
await erc20Contract.methods.balanceOf(contracts.accounts[0]).call()
|
|
||||||
).to.equal('0')
|
|
||||||
|
|
||||||
const tx = await sideStaking.getVesting(
|
const tx = await sideStaking.getVesting(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
sideStakingAddress,
|
sideStakingAddress,
|
||||||
erc20Token
|
erc20Token
|
||||||
)
|
)
|
||||||
@ -263,12 +264,12 @@ describe('SideStaking unit test', () => {
|
|||||||
it('#swapExactAmountIn - should swap', async () => {
|
it('#swapExactAmountIn - should swap', async () => {
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.transfer(user2, web3.utils.toWei('1000'))
|
.transfer(user2, web3.utils.toWei('1000'))
|
||||||
.send({ from: contracts.accounts[0] })
|
.send({ from: factoryOwner })
|
||||||
await approve(web3, user2, contracts.daiAddress, poolAddress, '10')
|
await approve(web3, user2, contracts.daiAddress, poolAddress, '10')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
tokenAmountIn: '10',
|
tokenAmountIn: '10',
|
||||||
@ -292,7 +293,7 @@ describe('SideStaking unit test', () => {
|
|||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
maxAmountIn: '100',
|
maxAmountIn: '100',
|
||||||
@ -367,9 +368,9 @@ describe('SideStaking unit test', () => {
|
|||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: contracts.accounts[0],
|
minter: factoryOwner,
|
||||||
feeManager: user3,
|
feeManager: user3,
|
||||||
mpFeeAddress: contracts.accounts[0],
|
mpFeeAddress: factoryOwner,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
@ -381,8 +382,8 @@ describe('SideStaking unit test', () => {
|
|||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.usdcAddress,
|
baseTokenAddress: contracts.usdcAddress,
|
||||||
baseTokenSender: contracts.factory721Address,
|
baseTokenSender: contracts.factory721Address,
|
||||||
publisherAddress: contracts.accounts[0],
|
publisherAddress: factoryOwner,
|
||||||
marketFeeCollector: contracts.accounts[0],
|
marketFeeCollector: factoryOwner,
|
||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: await usdcContract.methods.decimals().call(),
|
baseTokenDecimals: await usdcContract.methods.decimals().call(),
|
||||||
@ -398,7 +399,7 @@ describe('SideStaking unit test', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
poolParams
|
poolParams
|
||||||
@ -447,12 +448,10 @@ describe('SideStaking unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getVesting ', async () => {
|
it('#getVesting ', async () => {
|
||||||
expect(
|
expect(await erc20Contract.methods.balanceOf(factoryOwner).call()).to.equal('0')
|
||||||
await erc20Contract.methods.balanceOf(contracts.accounts[0]).call()
|
|
||||||
).to.equal('0')
|
|
||||||
|
|
||||||
const tx = await sideStaking.getVesting(
|
const tx = await sideStaking.getVesting(
|
||||||
contracts.accounts[0],
|
factoryOwner,
|
||||||
sideStakingAddress,
|
sideStakingAddress,
|
||||||
erc20Token
|
erc20Token
|
||||||
)
|
)
|
||||||
@ -473,13 +472,13 @@ describe('SideStaking unit test', () => {
|
|||||||
const transferAmount = await amountToUnits(web3, contracts.usdcAddress, '1000') // 1000 USDC
|
const transferAmount = await amountToUnits(web3, contracts.usdcAddress, '1000') // 1000 USDC
|
||||||
await usdcContract.methods
|
await usdcContract.methods
|
||||||
.transfer(user2, transferAmount)
|
.transfer(user2, transferAmount)
|
||||||
.send({ from: contracts.accounts[0] })
|
.send({ from: factoryOwner })
|
||||||
|
|
||||||
await approve(web3, user2, contracts.usdcAddress, poolAddress, '10')
|
await approve(web3, user2, contracts.usdcAddress, poolAddress, '10')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
tokenAmountIn: '10',
|
tokenAmountIn: '10',
|
||||||
@ -502,7 +501,7 @@ describe('SideStaking unit test', () => {
|
|||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: contracts.accounts[0]
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
maxAmountIn: '100',
|
maxAmountIn: '100',
|
||||||
|
@ -35,13 +35,16 @@ describe('Datatoken', () => {
|
|||||||
const nftName = 'NFTName'
|
const nftName = 'NFTName'
|
||||||
const nftSymbol = 'NFTSymbol'
|
const nftSymbol = 'NFTSymbol'
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
nftOwner = accounts[0]
|
||||||
|
user1 = accounts[1]
|
||||||
|
user2 = accounts[2]
|
||||||
|
user3 = accounts[3]
|
||||||
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contractHandler = new TestContractHandler(web3)
|
contractHandler = new TestContractHandler(web3)
|
||||||
await contractHandler.getAccounts()
|
|
||||||
nftOwner = contractHandler.accounts[0]
|
|
||||||
user1 = contractHandler.accounts[1]
|
|
||||||
user2 = contractHandler.accounts[2]
|
|
||||||
user3 = contractHandler.accounts[3]
|
|
||||||
await contractHandler.deployContracts(nftOwner)
|
await contractHandler.deployContracts(nftOwner)
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
@ -50,7 +53,7 @@ describe('Datatoken', () => {
|
|||||||
)
|
)
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.approve(contractHandler.factory721Address, web3.utils.toWei('10000'))
|
.approve(contractHandler.factory721Address, web3.utils.toWei('10000'))
|
||||||
.send({ from: contractHandler.accounts[0] })
|
.send({ from: nftOwner })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should initialize NFTFactory instance and create a new NFT', async () => {
|
it('should initialize NFTFactory instance and create a new NFT', async () => {
|
||||||
|
@ -23,13 +23,16 @@ describe('NFT', () => {
|
|||||||
const publishMarketFeeAdress = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
const publishMarketFeeAdress = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
||||||
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
nftOwner = accounts[0]
|
||||||
|
user1 = accounts[1]
|
||||||
|
user2 = accounts[2]
|
||||||
|
user3 = accounts[3]
|
||||||
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contractHandler = new TestContractHandler(web3)
|
contractHandler = new TestContractHandler(web3)
|
||||||
await contractHandler.getAccounts()
|
|
||||||
nftOwner = contractHandler.accounts[0]
|
|
||||||
user1 = contractHandler.accounts[1]
|
|
||||||
user2 = contractHandler.accounts[2]
|
|
||||||
user3 = contractHandler.accounts[3]
|
|
||||||
await contractHandler.deployContracts(nftOwner)
|
await contractHandler.deployContracts(nftOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user