dsa-connectors/test/mainnet/basic-ERC721/ERC721-transfer.ts

136 lines
5.2 KiB
TypeScript
Raw Normal View History

import { expect } from "chai";
2021-12-05 23:37:37 +00:00
import hre, { network } from "hardhat";
2021-08-31 14:41:31 +00:00
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
2021-12-05 23:37:37 +00:00
import { abi } from "../../../scripts/constant/abi/core/InstaImplementations.json"
2021-08-31 14:41:31 +00:00
2021-12-06 00:14:38 +00:00
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"
2021-12-05 19:10:22 +00:00
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
2021-12-06 00:14:38 +00:00
import { encodeSpells } from "../../../scripts/tests/encodeSpells"
2021-12-05 19:10:22 +00:00
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
2021-12-09 19:32:08 +00:00
import addresses from "../../../scripts/constant/addresses"
2021-12-10 17:29:55 +00:00
import abis from "../../../scripts/constant/abis"
2021-12-05 23:37:37 +00:00
import type { Signer, Contract } from "ethers";
2021-12-05 23:37:37 +00:00
import { ConnectV2BasicERC721__factory, IERC721__factory } from "../../../typechain";
2021-08-31 14:41:31 +00:00
const TOKEN_CONTRACT_ADDR = "0x4d695c615a7aacf2d7b9c481b66045bb2457dfde";
const TOKEN_OWNER_ADDR = "0x8c6b10d42ff08e56133fca0dac75e1931b1fcc23";
const TOKEN_ID = "38";
2021-08-31 16:17:03 +00:00
const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D"
2021-08-31 14:41:31 +00:00
describe("BASIC-ERC721", function () {
const connectorName = "BASIC-ERC721-A"
let dsaWallet0: any;
2021-12-05 23:37:37 +00:00
let masterSigner: Signer;
let instaConnectorsV2: Contract;
let connector: any;
let nftContract: any;
let tokenOwner: any;
let instaImplementationsMapping: any;
let InstaAccountV2DefaultImpl: any;
let instaAccountV2DefaultImpl: any;
2021-08-31 14:41:31 +00:00
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => {
2021-09-29 05:19:30 +00:00
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
2021-12-05 23:37:37 +00:00
// @ts-ignore
2021-09-29 05:19:30 +00:00
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13300000,
},
},
],
});
2021-08-31 14:41:31 +00:00
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [TOKEN_OWNER_ADDR],
});
await network.provider.send("hardhat_setBalance", [
TOKEN_OWNER_ADDR,
"0x10000000000000000",
2021-08-31 14:41:31 +00:00
]);
// get tokenOwner
tokenOwner = await ethers.getSigner(
TOKEN_OWNER_ADDR
);
2021-12-05 23:37:37 +00:00
nftContract = await ethers.getContractAt(IERC721__factory.abi, TOKEN_CONTRACT_ADDR)
masterSigner = await getMasterSigner()
2021-12-08 07:44:19 +00:00
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.mainnet.core.connectorsV2);
2021-08-31 16:17:03 +00:00
2021-12-05 23:37:37 +00:00
instaImplementationsMapping = await ethers.getContractAt(abi, implementationsMappingAddr);
2021-08-31 16:17:03 +00:00
InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation")
2021-12-08 07:44:19 +00:00
instaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.mainnet.core.instaIndex);
2021-08-31 16:17:03 +00:00
await instaAccountV2DefaultImpl.deployed()
2021-08-31 14:41:31 +00:00
connector = await deployAndEnableConnector({
connectorName,
2021-12-05 23:37:37 +00:00
contractArtifact: ConnectV2BasicERC721__factory,
2021-08-31 14:41:31 +00:00
signer: masterSigner,
connectors: instaConnectorsV2
})
console.log("Connector address", connector.address)
})
it("Should have contracts deployed.", async function () {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
2021-12-05 23:37:37 +00:00
expect(!!(await masterSigner.getAddress())).to.be.true;
2021-08-31 14:41:31 +00:00
});
2021-08-31 16:17:03 +00:00
describe("Implementations", function () {
it("Should add default implementation to mapping.", async function () {
const tx = await instaImplementationsMapping.connect(masterSigner).setDefaultImplementation(instaAccountV2DefaultImpl.address);
await tx.wait()
expect(await instaImplementationsMapping.defaultImplementation()).to.be.equal(instaAccountV2DefaultImpl.address);
});
});
2021-08-31 14:41:31 +00:00
describe("DSA wallet setup", function () {
it("Should build DSA v2", async function () {
dsaWallet0 = await buildDSAv2(tokenOwner.address)
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main", function () {
it("should deposit successfully", async () => {
console.log("DSA wallet address", dsaWallet0.address)
await nftContract.connect(tokenOwner).setApprovalForAll(dsaWallet0.address, true);
const spells = [
{
connector: connectorName,
method: "depositERC721",
args: [
TOKEN_CONTRACT_ADDR,
TOKEN_ID,
"0",
"0"
]
}
];
const tx = await dsaWallet0
.connect(tokenOwner)
.cast(...encodeSpells(spells), tokenOwner.address);
const receipt = await tx.wait();
});
})
})