Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeployTemplates.ContractDeploy fails to successfully deploy wasm contract #45

Closed
stormeye2000 opened this issue Oct 4, 2023 · 4 comments

Comments

@stormeye2000
Copy link

stormeye2000 commented Oct 4, 2023

What happened?

An erc20 contract was deployed.
The deploy result is retrieved
The ExecutionResult is false

What did you expect to happen?

The ExecutionResult is true

The contract is here: erc20.wasm.zip

Thanks

Carl Norburn

@davidatwhiletrue
Copy link
Member

hey @stormeye2000, can you share a deploy hash for which the SDK behaves as described?

@davidatwhiletrue
Copy link
Member

@stormeye2000 I've not been able to run the tests to check this solution works. But here is the code I propose:

    [When(@"the wasm is loaded as from the file system")]
    public async Task WhenTheWasmIsLoadedAsFromTheFileSystem() {
        WriteLine("the wasm is loaded as from the file system");

        var wasmBytes = File.ReadAllBytes(_contextMap.Get<string>(StepConstants.WASM_PATH));
        Assert.That(wasmBytes.Length, Is.EqualTo(189336));
        
        var chainName = "casper-net-1";
        var gas = BigInteger.Parse("200000000000");
        byte tokenDecimals = 11;
        var tokenName = "Acme Token";
        var tokenTotalSupply = BigInteger.Parse("500000000000");
        var tokenSymbol = "ACME";
        
        var faucetPem = AssetUtils.GetFaucetAsset(1, "secret_key.pem");
        Assert.That(faucetPem, Is.Not.Null);
        
        var faucetKey = KeyPair.FromPem(faucetPem);

        Assert.That(faucetKey, Is.Not.Null);
        Assert.That(faucetKey.PublicKey, Is.Not.Null);
        
        _contextMap.Add(StepConstants.FAUCET_PRIVATE_KEY, faucetKey);

        var runtimeArgs = new List<NamedArg>{ 
            new ("token_decimals", CLValue.U8(tokenDecimals)), 
            new ("token_name", CLValue.String(tokenName)),
            new ("token_symbol", CLValue.String(tokenSymbol)), 
            new ("token_total_supply", CLValue.U256(tokenTotalSupply)) 
        };
        var session = new ModuleBytesDeployItem(wasmBytes, runtimeArgs);
        var payment = new ModuleBytesDeployItem(gas);
        var header = new DeployHeader()
        {
            Account = faucetKey.PublicKey,
            Timestamp = DateUtils.ToEpochTime(DateTime.UtcNow),
            Ttl = (ulong) TimeSpan.FromMinutes(30).TotalMilliseconds,
            ChainName = chainName,
            GasPrice = 1
        };

        var deploy = new Deploy(header, payment, session);
        deploy.Sign(faucetKey);

        var putResponse = await GetCasperService().PutDeploy(deploy);

        _contextMap.Add(StepConstants.DEPLOY_RESULT, putResponse);
    }

@stormeye2000
Copy link
Author

The above fixes the issue, thanks
Please close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants