Created
August 2, 2023 14:56
-
-
Save scammi/7bb7cf69af1c677041c490670bf1ed2c to your computer and use it in GitHub Desktop.
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
it('Bonds and breaks a NFT', async() => { | |
const tokenId = 1; | |
const depositedTokenId = 2; | |
await nftMock.mint(deployer, tokenId).then(tx => tx.wait()); | |
await nftMock.mint(deployer, depositedTokenId).then(tx => tx.wait()); | |
// Create an account | |
const newAccountAddress = await registryContract.account( | |
chargedParticlesAccountAddress, | |
network.config.chainId ?? 137, | |
nftMockAddress, | |
tokenId, | |
0 | |
); | |
await registryContract.createAccount( | |
chargedParticlesAccountAddress, | |
network.config.chainId ?? 137, | |
nftMockAddress, | |
tokenId, | |
0, | |
'0x' | |
).then(tx => tx.wait()); | |
// Give permission | |
await nftMock.approve(newAccountAddress, depositedTokenId).then(tx => tx.wait()); | |
expect(await nftMock.getApproved(depositedTokenId)).to.be.eq(newAccountAddress); | |
await nftMock.transferFrom(deployer, newAccountAddress, depositedTokenId).then(tx => tx.wait()); | |
// Check owner | |
expect(await nftMock.ownerOf(depositedTokenId)).to.be.eq(newAccountAddress); | |
const account = await ethers.getContractAt('ChargedParticlesAccount', newAccountAddress); | |
const breakCovalentBond = (from: string, to:string, tokenId:number) => { | |
const ABI = ["function safeTransferFrom(address from, address to, uint256 tokenId)"]; | |
const iface = new ethers.Interface(ABI); | |
const cdata = iface.encodeFunctionData("safeTransferFrom", [from, to, tokenId]); | |
return cdata; | |
}; | |
const breakCovalentBondCallData = breakCovalentBond(newAccountAddress, receiver, depositedTokenId); | |
await account.executeCall( | |
nftMockAddress, | |
0, | |
breakCovalentBondCallData | |
).then(tx => tx.wait()); | |
expect(await nftMock.ownerOf(depositedTokenId)).to.be.eq(receiver); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment