You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
4.3 KiB
133 lines
4.3 KiB
3 years ago
|
import { InterchainGasPaymaster, Outbox } from '@abacus-network/core';
|
||
3 years ago
|
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
|
||
|
import { expect } from 'chai';
|
||
|
import { abacus, ethers } from 'hardhat';
|
||
3 years ago
|
import { AbcERC721 } from '../types';
|
||
|
import { AbcERC721Deploy } from './erc721.deploy';
|
||
3 years ago
|
|
||
|
const localDomain = 1000;
|
||
|
const remoteDomain = 2000;
|
||
3 years ago
|
const mintAmount = 50;
|
||
3 years ago
|
const domains = [localDomain, remoteDomain];
|
||
|
|
||
3 years ago
|
describe('AbcERC721', async () => {
|
||
3 years ago
|
let owner: SignerWithAddress,
|
||
|
recipient: SignerWithAddress,
|
||
3 years ago
|
router: AbcERC721,
|
||
|
remote: AbcERC721,
|
||
3 years ago
|
outbox: Outbox,
|
||
|
interchainGasPaymaster: InterchainGasPaymaster,
|
||
3 years ago
|
token: AbcERC721Deploy;
|
||
3 years ago
|
const testInterchainGasPayment = 123456789;
|
||
3 years ago
|
|
||
|
before(async () => {
|
||
|
[owner, recipient] = await ethers.getSigners();
|
||
|
await abacus.deploy(domains, owner);
|
||
|
});
|
||
|
|
||
|
beforeEach(async () => {
|
||
3 years ago
|
const defaultConfig = {
|
||
3 years ago
|
signer: owner,
|
||
3 years ago
|
name: 'AbcERC721',
|
||
3 years ago
|
symbol: 'ABC',
|
||
|
};
|
||
3 years ago
|
const configMap = {
|
||
|
[localDomain]: {
|
||
|
...defaultConfig,
|
||
|
mintAmount,
|
||
|
},
|
||
|
[remoteDomain]: {
|
||
|
...defaultConfig,
|
||
|
mintAmount: 0,
|
||
|
},
|
||
|
};
|
||
|
|
||
|
token = new AbcERC721Deploy(configMap);
|
||
3 years ago
|
await token.deploy(abacus);
|
||
|
router = token.router(localDomain);
|
||
|
remote = token.router(remoteDomain);
|
||
3 years ago
|
outbox = abacus.outbox(localDomain);
|
||
|
interchainGasPaymaster = abacus.interchainGasPaymaster(localDomain);
|
||
3 years ago
|
});
|
||
|
|
||
|
const expectBalance = async (
|
||
3 years ago
|
token: AbcERC721,
|
||
3 years ago
|
signer: SignerWithAddress,
|
||
|
balance: number,
|
||
|
) => expect(await token.balanceOf(signer.address)).to.eq(balance);
|
||
|
|
||
3 years ago
|
const tokenId = mintAmount / 2;
|
||
3 years ago
|
|
||
|
it('should not be initializable again', async () => {
|
||
|
await expect(
|
||
|
router.initialize(ethers.constants.AddressZero, 0, '', ''),
|
||
|
).to.be.revertedWith('Initializable: contract is already initialized');
|
||
|
});
|
||
|
|
||
3 years ago
|
it('should mint total supply to deployer on local domain', async () => {
|
||
3 years ago
|
await expectBalance(router, recipient, 0);
|
||
3 years ago
|
await expectBalance(router, owner, mintAmount);
|
||
3 years ago
|
await expectBalance(remote, recipient, 0);
|
||
3 years ago
|
await expectBalance(remote, owner, 0);
|
||
3 years ago
|
});
|
||
|
|
||
|
it('should allow for local transfers', async () => {
|
||
3 years ago
|
await router.transferFrom(owner.address, recipient.address, tokenId);
|
||
|
await expectBalance(router, recipient, 1);
|
||
|
await expectBalance(router, owner, mintAmount - 1);
|
||
3 years ago
|
await expectBalance(remote, recipient, 0);
|
||
3 years ago
|
await expectBalance(remote, owner, 0);
|
||
|
});
|
||
|
|
||
|
it('should not allow transfers of nonexistent identifiers', async () => {
|
||
|
const invalidTokenId = mintAmount + 1;
|
||
|
await expect(
|
||
|
router.transferFrom(owner.address, recipient.address, invalidTokenId),
|
||
|
).to.be.revertedWith('ERC721: operator query for nonexistent token');
|
||
|
await expect(
|
||
|
router.transferRemote(remoteDomain, recipient.address, invalidTokenId),
|
||
|
).to.be.revertedWith('ERC721: owner query for nonexistent token');
|
||
3 years ago
|
});
|
||
|
|
||
|
it('should allow for remote transfers', async () => {
|
||
3 years ago
|
const amount = mintAmount / 10;
|
||
|
for (let id = 0; id < amount; id++) {
|
||
|
await router.transferRemote(remoteDomain, recipient.address, id);
|
||
|
}
|
||
3 years ago
|
|
||
|
await expectBalance(router, recipient, 0);
|
||
3 years ago
|
await expectBalance(router, owner, mintAmount - amount);
|
||
3 years ago
|
await expectBalance(remote, recipient, 0);
|
||
3 years ago
|
await expectBalance(remote, owner, 0);
|
||
3 years ago
|
|
||
|
await abacus.processMessages();
|
||
|
|
||
|
await expectBalance(router, recipient, 0);
|
||
3 years ago
|
await expectBalance(router, owner, mintAmount - amount);
|
||
3 years ago
|
await expectBalance(remote, recipient, amount);
|
||
3 years ago
|
await expectBalance(remote, owner, 0);
|
||
3 years ago
|
});
|
||
|
|
||
3 years ago
|
it('allows interchain gas payment for remote transfers', async () => {
|
||
|
const leafIndex = await outbox.count();
|
||
|
await expect(
|
||
3 years ago
|
router.transferRemote(remoteDomain, recipient.address, tokenId, {
|
||
3 years ago
|
value: testInterchainGasPayment,
|
||
|
}),
|
||
|
)
|
||
|
.to.emit(interchainGasPaymaster, 'GasPayment')
|
||
|
.withArgs(leafIndex, testInterchainGasPayment);
|
||
|
});
|
||
|
|
||
3 years ago
|
it('should emit TransferRemote events', async () => {
|
||
3 years ago
|
expect(
|
||
|
await router.transferRemote(remoteDomain, recipient.address, tokenId),
|
||
|
)
|
||
3 years ago
|
.to.emit(router, 'SentTransferRemote')
|
||
3 years ago
|
.withArgs(remoteDomain, recipient.address, tokenId);
|
||
3 years ago
|
expect(await abacus.processMessages())
|
||
|
.to.emit(router, 'ReceivedTransferRemote')
|
||
3 years ago
|
.withArgs(localDomain, recipient.address, tokenId);
|
||
3 years ago
|
});
|
||
|
});
|