使用安全帽通过 Uniswap 流动性配置测试代币
Testing Token with Uniswap liquidity provisioning using hardhat
我正在尝试分叉 Safemoon(或者实际上是 NotSafeMoon),并将其用作学习智能合约开发的工具。 (我有大量您可能称之为“Web 2.0”的开发经验)。
假设我的构造函数中有这样的东西:
constructor () {
_rOwned[_msgSender()] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E); // binance PANCAKE V2
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
当我 运行 使用 npx hardhat test
进行测试时,出现以下故障:
Compilation finished successfully
TestToken contract
Deployment
1) "before each" hook for "Has the right name"
0 passing (807ms)
1 failing
1) TestToken contract
"before each" hook for "Has the right name":
Error: Transaction reverted: function call to a non-contract account
现在,这确实很有意义,毕竟我正在尝试调用 Pancakeswap v2 路由器合约。我如何绕过这个限制?有没有办法将路由器的合同地址作为环境变量注入?我可以使用 UniswapRouter 的模拟构造函数吗?一般来说,这种事情是如何通过智能合约开发以一种保持可测试的方式完成的(以及如何测试它)?
安全帽测试将合约部署到安全帽本地网络(默认情况下)。这个本地网络只有很少的预注资和解锁账户,但没有部署智能合约。包括 PancakeSwap v2 路由器 (0x10ED43...)。
您可以创建一个从生产 BSC 分叉的新 hardhat 网络,而不是部署和配置路由器合约的本地副本及其所有依赖项。
https://hardhat.org/guides/mainnet-forking.html
这将 运行 具有可用路由器合约的本地网络,但您的操作只会影响本地网络(而不是主网)。
我正在尝试分叉 Safemoon(或者实际上是 NotSafeMoon),并将其用作学习智能合约开发的工具。 (我有大量您可能称之为“Web 2.0”的开发经验)。
假设我的构造函数中有这样的东西:
constructor () {
_rOwned[_msgSender()] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E); // binance PANCAKE V2
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
当我 运行 使用 npx hardhat test
进行测试时,出现以下故障:
Compilation finished successfully
TestToken contract
Deployment
1) "before each" hook for "Has the right name"
0 passing (807ms)
1 failing
1) TestToken contract
"before each" hook for "Has the right name":
Error: Transaction reverted: function call to a non-contract account
现在,这确实很有意义,毕竟我正在尝试调用 Pancakeswap v2 路由器合约。我如何绕过这个限制?有没有办法将路由器的合同地址作为环境变量注入?我可以使用 UniswapRouter 的模拟构造函数吗?一般来说,这种事情是如何通过智能合约开发以一种保持可测试的方式完成的(以及如何测试它)?
安全帽测试将合约部署到安全帽本地网络(默认情况下)。这个本地网络只有很少的预注资和解锁账户,但没有部署智能合约。包括 PancakeSwap v2 路由器 (0x10ED43...)。
您可以创建一个从生产 BSC 分叉的新 hardhat 网络,而不是部署和配置路由器合约的本地副本及其所有依赖项。
https://hardhat.org/guides/mainnet-forking.html
这将 运行 具有可用路由器合约的本地网络,但您的操作只会影响本地网络(而不是主网)。