2021-08-31 14:41:31 +00:00
|
|
|
const { expect } = require("chai");
|
|
|
|
const hre = require("hardhat");
|
|
|
|
const { web3, deployments, waffle, ethers } = hre;
|
|
|
|
const { provider, deployContract } = waffle
|
2021-11-28 17:53:16 +00:00
|
|
|
const { abi: implementationsABI } = require("../../../scripts/constant/abi/core/InstaImplementations.json")
|
2021-08-31 14:41:31 +00:00
|
|
|
|
2021-11-28 17:53:16 +00:00
|
|
|
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
|
|
|
|
const buildDSAv2 = require("../../../scripts/buildDSAv2")
|
|
|
|
const encodeSpells = require("../../../scripts/encodeSpells.js")
|
|
|
|
const getMasterSigner = require("../../../scripts/getMasterSigner")
|
2021-08-31 14:41:31 +00:00
|
|
|
|
2021-11-28 17:53:16 +00:00
|
|
|
const addresses = require("../../../scripts/constant/addresses");
|
|
|
|
const abis = require("../../../scripts/constant/abis");
|
|
|
|
const constants = require("../../../scripts/constant/constant");
|
|
|
|
const tokens = require("../../../scripts/constant/tokens");
|
2021-08-31 14:41:31 +00:00
|
|
|
|
2021-08-31 16:17:03 +00:00
|
|
|
const connectV2BasicERC1155Artifacts = require("../../artifacts/contracts/mainnet/connectors/basic-ERC1155/main.sol/ConnectV2BasicERC1155.json")
|
|
|
|
const erc1155Artifacts = require("../../artifacts/@openzeppelin/contracts/token/ERC1155/IERC1155.sol/IERC1155.json")
|
2021-08-31 14:41:31 +00:00
|
|
|
|
2021-08-31 16:17:03 +00:00
|
|
|
const TOKEN_CONTRACT_ADDR = "0x1ca3262009b21F944e6b92a2a88D039D06F1acFa";
|
|
|
|
const TOKEN_OWNER_ADDR = "0x1ca3262009b21F944e6b92a2a88D039D06F1acFa";
|
|
|
|
const TOKEN_ID = "1";
|
2021-08-31 14:41:31 +00:00
|
|
|
|
2021-08-31 16:17:03 +00:00
|
|
|
const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D"
|
|
|
|
|
|
|
|
describe("BASIC-ERC1155", function () {
|
|
|
|
const connectorName = "BASIC-ERC1155-A"
|
2021-08-31 14:41:31 +00:00
|
|
|
|
|
|
|
let dsaWallet0
|
|
|
|
let masterSigner;
|
|
|
|
let instaConnectorsV2;
|
|
|
|
let connector;
|
|
|
|
let nftContract;
|
|
|
|
let tokenOwner;
|
2021-08-31 16:17:03 +00:00
|
|
|
let instaImplementationsMapping;
|
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: {
|
|
|
|
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,
|
|
|
|
"0x1000000000000000",
|
|
|
|
]);
|
|
|
|
|
|
|
|
// get tokenOwner
|
|
|
|
tokenOwner = await ethers.getSigner(
|
|
|
|
TOKEN_OWNER_ADDR
|
|
|
|
);
|
2021-08-31 16:17:03 +00:00
|
|
|
nftContract = await ethers.getContractAt(erc1155Artifacts.abi, TOKEN_CONTRACT_ADDR)
|
2021-08-31 14:41:31 +00:00
|
|
|
masterSigner = await getMasterSigner(wallet3)
|
|
|
|
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
2021-08-31 16:17:03 +00:00
|
|
|
|
|
|
|
instaImplementationsMapping = await ethers.getContractAt(implementationsABI, implementationsMappingAddr);
|
|
|
|
InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation")
|
|
|
|
instaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
|
|
|
|
await instaAccountV2DefaultImpl.deployed()
|
2021-08-31 14:41:31 +00:00
|
|
|
connector = await deployAndEnableConnector({
|
|
|
|
connectorName,
|
2021-08-31 16:17:03 +00:00
|
|
|
contractArtifact: connectV2BasicERC1155Artifacts,
|
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;
|
|
|
|
expect(!!masterSigner.address).to.be.true;
|
|
|
|
});
|
|
|
|
|
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,
|
2021-08-31 16:17:03 +00:00
|
|
|
method: "depositERC1155",
|
2021-08-31 14:41:31 +00:00
|
|
|
args: [
|
|
|
|
TOKEN_CONTRACT_ADDR,
|
|
|
|
TOKEN_ID,
|
2021-08-31 16:17:03 +00:00
|
|
|
1,
|
2021-08-31 14:41:31 +00:00
|
|
|
"0",
|
|
|
|
"0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const tx = await dsaWallet0
|
|
|
|
.connect(tokenOwner)
|
|
|
|
.cast(...encodeSpells(spells), tokenOwner.address);
|
|
|
|
const receipt = await tx.wait();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|