mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
feat: implement ERC721/1155 testcase
This commit is contained in:
parent
453848c7f5
commit
d39dc1d509
114
contracts/test/implementation_default.sol
Normal file
114
contracts/test/implementation_default.sol
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import { Variables } from "./variables.sol";
|
||||||
|
|
||||||
|
interface IndexInterface {
|
||||||
|
function list() external view returns (address);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ListInterface {
|
||||||
|
function addAuth(address user) external;
|
||||||
|
|
||||||
|
function removeAuth(address user) external;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Constants is Variables {
|
||||||
|
uint256 public constant implementationVersion = 1;
|
||||||
|
// InstaIndex Address.
|
||||||
|
address public immutable instaIndex;
|
||||||
|
// The Account Module Version.
|
||||||
|
uint256 public constant version = 2;
|
||||||
|
|
||||||
|
constructor(address _instaIndex) {
|
||||||
|
instaIndex = _instaIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Record is Constants {
|
||||||
|
constructor(address _instaIndex) Constants(_instaIndex) {}
|
||||||
|
|
||||||
|
event LogEnableUser(address indexed user);
|
||||||
|
event LogDisableUser(address indexed user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Check for Auth if enabled.
|
||||||
|
* @param user address/user/owner.
|
||||||
|
*/
|
||||||
|
function isAuth(address user) public view returns (bool) {
|
||||||
|
return _auth[user];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Enable New User.
|
||||||
|
* @param user Owner address
|
||||||
|
*/
|
||||||
|
function enable(address user) public {
|
||||||
|
require(
|
||||||
|
msg.sender == address(this) || msg.sender == instaIndex,
|
||||||
|
"not-self-index"
|
||||||
|
);
|
||||||
|
require(user != address(0), "not-valid");
|
||||||
|
require(!_auth[user], "already-enabled");
|
||||||
|
_auth[user] = true;
|
||||||
|
ListInterface(IndexInterface(instaIndex).list()).addAuth(user);
|
||||||
|
emit LogEnableUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Disable User.
|
||||||
|
* @param user Owner address
|
||||||
|
*/
|
||||||
|
function disable(address user) public {
|
||||||
|
require(msg.sender == address(this), "not-self");
|
||||||
|
require(user != address(0), "not-valid");
|
||||||
|
require(_auth[user], "already-disabled");
|
||||||
|
delete _auth[user];
|
||||||
|
ListInterface(IndexInterface(instaIndex).list()).removeAuth(user);
|
||||||
|
emit LogDisableUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev ERC721 token receiver
|
||||||
|
*/
|
||||||
|
function onERC721Received(
|
||||||
|
address,
|
||||||
|
address,
|
||||||
|
uint256,
|
||||||
|
bytes calldata
|
||||||
|
) external returns (bytes4) {
|
||||||
|
return 0x150b7a02; // bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev ERC1155 token receiver
|
||||||
|
*/
|
||||||
|
function onERC1155Received(
|
||||||
|
address,
|
||||||
|
address,
|
||||||
|
uint256,
|
||||||
|
uint256,
|
||||||
|
bytes memory
|
||||||
|
) external returns (bytes4) {
|
||||||
|
return 0xf23a6e61; // bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev ERC1155 token receiver
|
||||||
|
*/
|
||||||
|
function onERC1155BatchReceived(
|
||||||
|
address,
|
||||||
|
address,
|
||||||
|
uint256[] calldata,
|
||||||
|
uint256[] calldata,
|
||||||
|
bytes calldata
|
||||||
|
) external returns (bytes4) {
|
||||||
|
return 0xbc197c81; // bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract InstaDefaultImplementation is Record {
|
||||||
|
constructor(address _instaIndex) public Record(_instaIndex) {}
|
||||||
|
|
||||||
|
receive() external payable {}
|
||||||
|
}
|
6
contracts/test/variables.sol
Normal file
6
contracts/test/variables.sol
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
contract Variables {
|
||||||
|
// Auth Module(Address of Auth => bool).
|
||||||
|
mapping (address => bool) internal _auth;
|
||||||
|
}
|
206
scripts/constant/abi/core/InstaImplementations.json
Normal file
206
scripts/constant/abi/core/InstaImplementations.json
Normal file
File diff suppressed because one or more lines are too long
127
test/basic-ERC1155/ERC1155-transfer.js
Normal file
127
test/basic-ERC1155/ERC1155-transfer.js
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
const { expect } = require("chai");
|
||||||
|
const hre = require("hardhat");
|
||||||
|
const { web3, deployments, waffle, ethers } = hre;
|
||||||
|
const { provider, deployContract } = waffle
|
||||||
|
const {abi: implementationsABI} = require("../../scripts/constant/abi/core/InstaImplementations.json")
|
||||||
|
|
||||||
|
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js")
|
||||||
|
const buildDSAv2 = require("../../scripts/buildDSAv2")
|
||||||
|
const encodeSpells = require("../../scripts/encodeSpells.js")
|
||||||
|
const getMasterSigner = require("../../scripts/getMasterSigner")
|
||||||
|
|
||||||
|
const addresses = require("../../scripts/constant/addresses");
|
||||||
|
const abis = require("../../scripts/constant/abis");
|
||||||
|
const constants = require("../../scripts/constant/constant");
|
||||||
|
const tokens = require("../../scripts/constant/tokens");
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
const TOKEN_CONTRACT_ADDR = "0x1ca3262009b21F944e6b92a2a88D039D06F1acFa";
|
||||||
|
const TOKEN_OWNER_ADDR = "0x1ca3262009b21F944e6b92a2a88D039D06F1acFa";
|
||||||
|
const TOKEN_ID = "1";
|
||||||
|
|
||||||
|
const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D"
|
||||||
|
|
||||||
|
describe("BASIC-ERC1155", function () {
|
||||||
|
const connectorName = "BASIC-ERC1155-A"
|
||||||
|
|
||||||
|
let dsaWallet0
|
||||||
|
let masterSigner;
|
||||||
|
let instaConnectorsV2;
|
||||||
|
let connector;
|
||||||
|
let nftContract;
|
||||||
|
let tokenOwner;
|
||||||
|
let instaImplementationsMapping;
|
||||||
|
|
||||||
|
|
||||||
|
const wallets = provider.getWallets()
|
||||||
|
const [wallet0, wallet1, wallet2, wallet3] = wallets
|
||||||
|
before(async () => {
|
||||||
|
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
|
||||||
|
);
|
||||||
|
nftContract = await ethers.getContractAt(erc1155Artifacts.abi, TOKEN_CONTRACT_ADDR)
|
||||||
|
masterSigner = await getMasterSigner(wallet3)
|
||||||
|
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
||||||
|
|
||||||
|
instaImplementationsMapping = await ethers.getContractAt(implementationsABI, implementationsMappingAddr);
|
||||||
|
InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation")
|
||||||
|
instaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
|
||||||
|
await instaAccountV2DefaultImpl.deployed()
|
||||||
|
connector = await deployAndEnableConnector({
|
||||||
|
connectorName,
|
||||||
|
contractArtifact: connectV2BasicERC1155Artifacts,
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
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: "depositERC1155",
|
||||||
|
args: [
|
||||||
|
TOKEN_CONTRACT_ADDR,
|
||||||
|
TOKEN_ID,
|
||||||
|
1,
|
||||||
|
"0",
|
||||||
|
"0"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(tokenOwner)
|
||||||
|
.cast(...encodeSpells(spells), tokenOwner.address);
|
||||||
|
const receipt = await tx.wait();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
|
@ -2,6 +2,7 @@ const { expect } = require("chai");
|
||||||
const hre = require("hardhat");
|
const hre = require("hardhat");
|
||||||
const { web3, deployments, waffle, ethers } = hre;
|
const { web3, deployments, waffle, ethers } = hre;
|
||||||
const { provider, deployContract } = waffle
|
const { provider, deployContract } = waffle
|
||||||
|
const {abi: implementationsABI} = require("../../scripts/constant/abi/core/InstaImplementations.json")
|
||||||
|
|
||||||
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js")
|
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js")
|
||||||
const buildDSAv2 = require("../../scripts/buildDSAv2")
|
const buildDSAv2 = require("../../scripts/buildDSAv2")
|
||||||
|
@ -20,6 +21,8 @@ const TOKEN_CONTRACT_ADDR = "0x4d695c615a7aacf2d7b9c481b66045bb2457dfde";
|
||||||
const TOKEN_OWNER_ADDR = "0x8c6b10d42ff08e56133fca0dac75e1931b1fcc23";
|
const TOKEN_OWNER_ADDR = "0x8c6b10d42ff08e56133fca0dac75e1931b1fcc23";
|
||||||
const TOKEN_ID = "38";
|
const TOKEN_ID = "38";
|
||||||
|
|
||||||
|
const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D"
|
||||||
|
|
||||||
describe("BASIC-ERC721", function () {
|
describe("BASIC-ERC721", function () {
|
||||||
const connectorName = "BASIC-ERC721-A"
|
const connectorName = "BASIC-ERC721-A"
|
||||||
|
|
||||||
|
@ -29,6 +32,7 @@ describe("BASIC-ERC721", function () {
|
||||||
let connector;
|
let connector;
|
||||||
let nftContract;
|
let nftContract;
|
||||||
let tokenOwner;
|
let tokenOwner;
|
||||||
|
let instaImplementationsMapping;
|
||||||
|
|
||||||
|
|
||||||
const wallets = provider.getWallets()
|
const wallets = provider.getWallets()
|
||||||
|
@ -51,6 +55,11 @@ describe("BASIC-ERC721", function () {
|
||||||
nftContract = await ethers.getContractAt(erc721Artifacts.abi, TOKEN_CONTRACT_ADDR)
|
nftContract = await ethers.getContractAt(erc721Artifacts.abi, TOKEN_CONTRACT_ADDR)
|
||||||
masterSigner = await getMasterSigner(wallet3)
|
masterSigner = await getMasterSigner(wallet3)
|
||||||
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
||||||
|
|
||||||
|
instaImplementationsMapping = await ethers.getContractAt(implementationsABI, implementationsMappingAddr);
|
||||||
|
InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation")
|
||||||
|
instaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
|
||||||
|
await instaAccountV2DefaultImpl.deployed()
|
||||||
connector = await deployAndEnableConnector({
|
connector = await deployAndEnableConnector({
|
||||||
connectorName,
|
connectorName,
|
||||||
contractArtifact: connectV2BasicERC721Artifacts,
|
contractArtifact: connectV2BasicERC721Artifacts,
|
||||||
|
@ -66,6 +75,16 @@ describe("BASIC-ERC721", function () {
|
||||||
expect(!!masterSigner.address).to.be.true;
|
expect(!!masterSigner.address).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe("DSA wallet setup", function () {
|
describe("DSA wallet setup", function () {
|
||||||
it("Should build DSA v2", async function () {
|
it("Should build DSA v2", async function () {
|
||||||
dsaWallet0 = await buildDSAv2(tokenOwner.address)
|
dsaWallet0 = await buildDSAv2(tokenOwner.address)
|
Loading…
Reference in New Issue
Block a user