Skip to content

Commit

Permalink
feat: Add tests for new events
Browse files Browse the repository at this point in the history
  • Loading branch information
QEDK committed Feb 28, 2022
1 parent aced338 commit 973804a
Show file tree
Hide file tree
Showing 6 changed files with 1,319 additions and 793 deletions.
123 changes: 123 additions & 0 deletions test/predicates/ERC1155Predicate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ contract('ERC1155Predicate', (accounts) => {
let dummyERC1155
let erc1155Predicate
let exitTokensTx
let exitedLog
let oldAccountBalance
let oldContractBalance

Expand Down Expand Up @@ -205,6 +206,38 @@ contract('ERC1155Predicate', (accounts) => {
should.exist(exitTokensTx)
})

it('Should emit ExitedERC1155 log', () => {
const logs = logDecoder.decodeLogs(exitTokensTx.receipt.rawLogs)
exitedLog = logs.find(l => l.event === 'ExitedERC1155')
should.exist(exitedLog)
})

describe('Correct values should be emitted in ExitedERC1155 log', () => {
it('Event should be emitted by correct contract', () => {
exitedLog.address.should.equal(
erc1155Predicate.address.toLowerCase()
)
})

it('Should emit proper withdrawer', () => {
exitedLog.args.withdrawer.should.equal(withdrawer)
})

it('Should emit proper root token', () => {
exitedLog.args.rootToken.should.equal(dummyERC1155.address)
})

it('Should emit proper token id', () => {
const id = exitedLog.args.id.toNumber()
id.should.equal(tokenId)
})

it('Should emit proper amount', () => {
const exitedLogAmount = new BN(exitedLog.args.amount.toString())
exitedLogAmount.should.be.a.bignumber.that.equals(withdrawAmount)
})
})

it('Withdaw amount should be deducted from contract', async() => {
const newContractBalance = await dummyERC1155.balanceOf(erc1155Predicate.address, tokenId)
newContractBalance.should.be.a.bignumber.that.equals(
Expand Down Expand Up @@ -233,6 +266,7 @@ contract('ERC1155Predicate', (accounts) => {
let dummyERC1155
let erc1155Predicate
let exitTokensTx
let exitedLog
let oldAccountBalanceA
let oldAccountBalanceB
let oldContractBalanceA
Expand Down Expand Up @@ -269,6 +303,50 @@ contract('ERC1155Predicate', (accounts) => {
should.exist(exitTokensTx)
})

it('Should emit ExitedBatchERC1155 log', () => {
const logs = logDecoder.decodeLogs(exitTokensTx.receipt.rawLogs)
exitedLog = logs.find(l => l.event === 'ExitedBatchERC1155')
should.exist(exitedLog)
})

describe('Correct values should be emitted in ExitedBatchERC1155 log', () => {
it('Event should be emitted by correct contract', () => {
exitedLog.address.should.equal(
erc1155Predicate.address.toLowerCase()
)
})

it('Should emit proper withdrawer', () => {
exitedLog.args.withdrawer.should.equal(withdrawer)
})

it('Should emit proper root token', () => {
exitedLog.args.rootToken.should.equal(dummyERC1155.address)
})

it('Should emit proper token id for A', () => {
const id = exitedLog.args.ids[0].toNumber()
id.should.equal(tokenIdA)
})

it('Should emit proper token id for B', () => {
const id = exitedLog.args.ids[1].toNumber()
id.should.equal(tokenIdB)
})

it('Should emit proper amount for A', () => {
const amounts = exitedLog.args.amounts
const amount = new BN(amounts[0].toString())
amount.should.be.a.bignumber.that.equals(withdrawAmountA)
})

it('Should emit proper amount for B', () => {
const amounts = exitedLog.args.amounts
const amount = new BN(amounts[1].toString())
amount.should.be.a.bignumber.that.equals(withdrawAmountB)
})
})

it('Withdaw amount should be deducted from contract for A', async() => {
const newContractBalance = await dummyERC1155.balanceOf(erc1155Predicate.address, tokenIdA)
newContractBalance.should.be.a.bignumber.that.equals(
Expand Down Expand Up @@ -312,6 +390,7 @@ contract('ERC1155Predicate', (accounts) => {
let dummyERC1155
let erc1155Predicate
let exitTokensTx
let exitedLog
let oldAccountBalanceA
let oldAccountBalanceB
let oldContractBalanceA
Expand Down Expand Up @@ -343,6 +422,50 @@ contract('ERC1155Predicate', (accounts) => {
should.exist(exitTokensTx)
})

it('Should emit ExitedBatchERC1155 log', () => {
const logs = logDecoder.decodeLogs(exitTokensTx.receipt.rawLogs)
exitedLog = logs.find(l => l.event === 'ExitedBatchERC1155')
should.exist(exitedLog)
})

describe('Correct values should be emitted in ExitedBatchERC1155 log', () => {
it('Event should be emitted by correct contract', () => {
exitedLog.address.should.equal(
erc1155Predicate.address.toLowerCase()
)
})

it('Should emit proper withdrawer', () => {
exitedLog.args.withdrawer.should.equal(withdrawer)
})

it('Should emit proper root token', () => {
exitedLog.args.rootToken.should.equal(dummyERC1155.address)
})

it('Should emit proper token id for A', () => {
const id = exitedLog.args.ids[0].toNumber()
id.should.equal(tokenIdA)
})

it('Should emit proper token id for B', () => {
const id = exitedLog.args.ids[1].toNumber()
id.should.equal(tokenIdB)
})

it('Should emit proper amount for A', () => {
const amounts = exitedLog.args.amounts
const amount = new BN(amounts[0].toString())
amount.should.be.a.bignumber.that.equals(withdrawAmountA)
})

it('Should emit proper amount for B', () => {
const amounts = exitedLog.args.amounts
const amount = new BN(amounts[1].toString())
amount.should.be.a.bignumber.that.equals(withdrawAmountB)
})
})

it('Withdaw amount should be deducted from contract for A', async() => {
const newContractBalance = await dummyERC1155.balanceOf(erc1155Predicate.address, tokenIdA)
newContractBalance.should.be.a.bignumber.that.equals(
Expand Down
56 changes: 56 additions & 0 deletions test/predicates/ERC20Predicate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ contract('ERC20Predicate', (accounts) => {
let oldAccountBalance
let oldContractBalance
let exitTokensTx
let exitedLog

before(async() => {
const contracts = await deployer.deployFreshRootContracts(accounts)
Expand All @@ -159,6 +160,33 @@ contract('ERC20Predicate', (accounts) => {
should.exist(exitTokensTx)
})

it('Should emit ExitedERC20 log', () => {
const logs = logDecoder.decodeLogs(exitTokensTx.receipt.rawLogs)
exitedLog = logs.find(l => l.event === 'ExitedERC20')
should.exist(exitedLog)
})

describe('Correct values should be emitted in ExitedERC20 log', () => {
it('Event should be emitted by correct contract', () => {
exitedLog.address.should.equal(
erc20Predicate.address.toLowerCase()
)
})

it('Should emit proper withdrawer', () => {
exitedLog.args.withdrawer.should.equal(withdrawer)
})

it('Should emit correct amount', () => {
const exitedLogAmount = new BN(exitedLog.args.amount.toString())
exitedLogAmount.should.be.bignumber.that.equals(withdrawAmount)
})

it('Should emit correct root token', () => {
exitedLog.args.rootToken.should.equal(dummyERC20.address)
})
})

it('Withdraw amount should be deducted from contract', async() => {
const newContractBalance = await dummyERC20.balanceOf(erc20Predicate.address)
newContractBalance.should.be.a.bignumber.that.equals(
Expand All @@ -184,6 +212,7 @@ contract('ERC20Predicate', (accounts) => {
let oldAccountBalance
let oldContractBalance
let exitTokensTx
let exitedLog

before(async() => {
const contracts = await deployer.deployFreshRootContracts(accounts)
Expand All @@ -206,6 +235,33 @@ contract('ERC20Predicate', (accounts) => {
should.exist(exitTokensTx)
})

it('Should emit ExitedERC20 log', () => {
const logs = logDecoder.decodeLogs(exitTokensTx.receipt.rawLogs)
exitedLog = logs.find(l => l.event === 'ExitedERC20')
should.exist(exitedLog)
})

describe('Correct values should be emitted in ExitedERC20 log', () => {
it('Event should be emitted by correct contract', () => {
exitedLog.address.should.equal(
erc20Predicate.address.toLowerCase()
)
})

it('Should emit proper withdrawer', () => {
exitedLog.args.withdrawer.should.equal(withdrawer)
})

it('Should emit correct amount', () => {
const exitedLogAmount = new BN(exitedLog.args.amount.toString())
exitedLogAmount.should.be.bignumber.that.equals(withdrawAmount)
})

it('Should emit correct root token', () => {
exitedLog.args.rootToken.should.equal(dummyERC20.address)
})
})

it('Withdraw amount should be deducted from contract', async() => {
const newContractBalance = await dummyERC20.balanceOf(erc20Predicate.address)
newContractBalance.should.be.a.bignumber.that.equals(
Expand Down
84 changes: 84 additions & 0 deletions test/predicates/ERC721Predicate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ contract('ERC721Predicate', (accounts) => {
let dummyERC721
let erc721Predicate
let exitTokensTx
let exitedLog

before(async () => {
const contracts = await deployer.deployFreshRootContracts(accounts)
Expand All @@ -246,6 +247,33 @@ contract('ERC721Predicate', (accounts) => {
should.exist(exitTokensTx)
})

it('Should emit ExitedERC721 log', () => {
const logs = logDecoder.decodeLogs(exitTokensTx.receipt.rawLogs)
exitedLog = logs.find(l => l.event === 'ExitedERC721')
should.exist(exitedLog)
})

describe('Correct values should be emitted in ExitedERC721 log', () => {
it('Event should be emitted by correct contract', () => {
exitedLog.address.should.equal(
erc721Predicate.address.toLowerCase()
)
})

it('Should emit proper withdrawer', () => {
exitedLog.args.withdrawer.should.equal(withdrawer)
})

it('Should emit correct tokenId', () => {
const exitedLogTokenId = exitedLog.args.tokenId.toNumber()
exitedLogTokenId.should.equal(tokenId)
})

it('Should emit correct root token', () => {
exitedLog.args.rootToken.should.equal(dummyERC721.address)
})
})

it('Token should be transferred to withdrawer', async () => {
const owner = await dummyERC721.ownerOf(tokenId)
owner.should.equal(withdrawer)
Expand All @@ -261,6 +289,7 @@ contract('ERC721Predicate', (accounts) => {
let dummyERC721
let erc721Predicate
let exitTokensTx
let exitedLog

before(async () => {
const contracts = await deployer.deployFreshRootContracts(accounts)
Expand Down Expand Up @@ -293,6 +322,33 @@ contract('ERC721Predicate', (accounts) => {
should.exist(exitTokensTx)
})

it('Should emit ExitedERC721 log', () => {
const logs = logDecoder.decodeLogs(exitTokensTx.receipt.rawLogs)
exitedLog = logs.find(l => l.event === 'ExitedERC721')
should.exist(exitedLog)
})

describe('Correct values should be emitted in ExitedERC721 log', () => {
it('Event should be emitted by correct contract', () => {
exitedLog.address.should.equal(
erc721Predicate.address.toLowerCase()
)
})

it('Should emit proper withdrawer', () => {
exitedLog.args.withdrawer.should.equal(withdrawer)
})

it('Should emit correct tokenId', () => {
const exitedLogTokenId = exitedLog.args.tokenId.toNumber()
exitedLogTokenId.should.equal(tokenId)
})

it('Should emit correct root token', () => {
exitedLog.args.rootToken.should.equal(dummyERC721.address)
})
})

it('Token should be transferred to withdrawer', async () => {
const owner = await dummyERC721.ownerOf(tokenId)
owner.should.equal(withdrawer)
Expand All @@ -312,6 +368,7 @@ contract('ERC721Predicate', (accounts) => {
let dummyERC721
let erc721Predicate
let exitTokensTx
let exitedLog

before(async () => {
const contracts = await deployer.deployFreshRootContracts(accounts)
Expand All @@ -333,6 +390,33 @@ contract('ERC721Predicate', (accounts) => {
should.exist(exitTokensTx)
})

it('Should emit ExitedERC721 log', () => {
const logs = logDecoder.decodeLogs(exitTokensTx.receipt.rawLogs)
exitedLog = logs.find(l => l.event === 'ExitedERC721')
should.exist(exitedLog)
})

describe('Correct values should be emitted in ExitedERC721 log', () => {
it('Event should be emitted by correct contract', () => {
exitedLog.address.should.equal(
erc721Predicate.address.toLowerCase()
)
})

it('Should emit proper withdrawer', () => {
exitedLog.args.withdrawer.should.equal(withdrawer)
})

it('Should emit correct tokenId', () => {
const exitedLogTokenId = exitedLog.args.tokenId.toNumber()
exitedLogTokenId.should.equal(tokenId)
})

it('Should emit correct root token', () => {
exitedLog.args.rootToken.should.equal(dummyERC721.address)
})
})

it('Token should be transferred to withdrawer', async () => {
const owner = await dummyERC721.ownerOf(tokenId)
owner.should.equal(withdrawer)
Expand Down
Loading

0 comments on commit 973804a

Please sign in to comment.