patractlabs / redspot

Redspot is an Substrate pallet-contracts (ink!) development environment. Compile your contracts and run them on a different networks. Redspot's core forks from Hardhat but changed a lot to suit substrate.
https://redspot.patract.io/
Other
67 stars 22 forks source link

Cannot deploy contract #140

Closed forgetso closed 3 years ago

forgetso commented 3 years ago

Redspot Version v0.11.9-3

Using basic deploy code (e.g. erc20 example) results in an error.

  const contract = await contractFactory.deploy("default", deployer.address, {
    gasLimit: "400000000000",
    value: "10000 UNIT",
  });

1) ERC20 Assigns initial balance: TypeError: Cannot read property 'negative' of undefined at Type.add (node_modules/bn.js/lib/bn.js:917:13) at ContractFactory.instantiateWithCode (node_modules/@redspot/patract/contractFactory.js:175:18) at ContractFactory.deploy (node_modules/@redspot/patract/contractFactory.js:254:90) at /home/chris/dev/erc20/tests/erc20.test.ts:19:44 at step (tests/erc20.test.ts:33:23) at Object.next (tests/erc20.test.ts:14:53) at fulfilled (tests/erc20.test.ts:5:58)

Changing this.api.consts.contracts.tombstoneDeposit to this.api.consts.contracts.schedule.hostFnWeights.tombstoneDeposit in packages/redspot-patract/src/contractFactory.ts causes this error to go away.

The contract then appears to deploy ok using the deploy script. However, a new issue appears when running the yarn test:

ERC20

ERROR contracts.NewContractNotFunded( The newly created contract is below the subsistence threshold after executing its contructor. No contracts are allowed to exist below that threshold.)

1) Assigns initial balance

I've tried changing the initial contract funding up to 100,000 UNIT but still get the same error.

ii-ii-ii commented 3 years ago

It probably has to do with the version of the chain you are using. Which chain are you using?

forgetso commented 3 years ago

I'm using the substrate contracts node which is now the recommended one for testing contracts. I was previously using canvas node but it stopped working when I upgraded it.

https://github.com/paritytech/substrate-contracts-node

substrate-contracts-node 0.1.0-35eeb84-x86_64-linux-gnu

forgetso commented 3 years ago

It appears this is a problem with yarn test only. When I run a modified deploy.ts., I can instantiate the contract and also send a balance.

e.g. running the below code with npx redspot run ./scripts/deploy.ts --verbose --log-level 2 works. Running yarn test does not work.

import {network, patract} from "redspot";

const {getContractFactory, getRandomSigner} = patract;
const {createSigner, keyring, api} = network;

async function run() {
    await api.isReady;

    // The redspot signer supports passing in an address. If you want to use  substrate uri, you can do it like this:
    // const signer = createSigner(keyring.createFromUri("bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice"));
    // Or get the configured account from redspot config:
    // const signer = (await getSigners())[0]
    const signer = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; // Alice Address

    const contractFactory = await getContractFactory("erc20", signer);

    const balance = await api.query.system.account(signer);

    console.log("Balance: ", balance.toHuman());

    // The `deploy` method will attempt to deploy a new contract.
    // The `deployed` method will first find out if the same contract already exists based on the parameters.
    // If the contract exists, it will be returned, otherwise a new contract will be created.
    const contract = await contractFactory.deploy("new", "1000000", {
        gasLimit: "400000000000",
        value: "100000 UNIT",
    });

    console.log("");
    console.log(
        "Deploy successfully. The contract address: ",
        contract.address.toString()
    );

    const receiver = await getRandomSigner();

    await contract.tx.transfer(receiver.address, 7);

    const receiverBalance = await contract.query.balanceOf(receiver.address);
    console.log("Balance: ", receiverBalance.output?.toHuman());

    api.disconnect();
}

run().catch((err) => {
    console.log(err);
});
forgetso commented 3 years ago

Ok, I can see that this is an issue with the test script:

const contract = await contractFactory.deploy("new", "1000");

Should be changed to:

const contract = await contractFactory.deploy("new", "1000", {
    gasLimit: "400000000000",
    value: "1000 UNIT",
});
forgetso commented 3 years ago

I've re-opened as the initial this.api.consts.contracts.tombstoneDeposit issue is still relevant.

frankli-dev commented 3 years ago

It probably has to do with the version of the chain you are using. Which chain are you using?

I'm also having the same issue. Can you explain what this means? I'm using my local chain (current substrate master branch)

atenjin commented 3 years ago

It probably has to do with the version of the chain you are using. Which chain are you using?

I'm also having the same issue. Can you explain what this means? I'm using my local chain (current substrate master branch)

ok we have test for substrate-contracts-node, because it was only recently proposed by parity, we haven’t adapted their changes yet.

we will update those related issue after we test.

atenjin commented 3 years ago

maybe related to https://github.com/patractlabs/redspot/issues/141 we have found reason, it's related to the removed rent https://github.com/paritytech/substrate/pull/9669

we will fix it soon and release a new version

ii-ii-ii commented 3 years ago

v0.12.2 is compatible with the new version of the chain.

forgetso commented 3 years ago

Thanks guys