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

Chain.balance works incorrectly in dry-run #1881

Open
davidyuk opened this issue Aug 17, 2023 · 0 comments · May be fixed by #1882
Open

Chain.balance works incorrectly in dry-run #1881

davidyuk opened this issue Aug 17, 2023 · 0 comments · May be fixed by #1882
Labels
bug Something isn't working
Milestone

Comments

@davidyuk
Copy link
Member

Reproduction

import {
  Node, AeSdk, MemoryAccount, CompilerHttp,
} from '@aeternity/aepp-sdk';

const contractSourceCode = `
contract Test =
 entrypoint getBalance(addr : address) =
  Chain.balance(addr)
`;

const node = new Node('https://testnet.aeternity.io');
const account = new MemoryAccount('9ebd7beda0c79af72a42ece3821a56eff16359b6df376cf049aee995565f022f840c974b97164776454ba119d84edc4d6058a8dec92b6edc578ab2d30b4c4200');
const aeSdk = new AeSdk({
  nodes: [{ name: 'testnet', instance: node }],
  accounts: [
    new MemoryAccount('9ebd7beda0c79af72a42ece3821a56eff16359b6df376cf049aee995565f022f840c974b97164776454ba119d84edc4d6058a8dec92b6edc578ab2d30b4c4200'),
  ],
  onCompiler: new CompilerHttp('https://v7.compiler.aepps.com'),
});

const contract = await aeSdk.initializeContract({ sourceCode: contractSourceCode });
const deployInfo = await contract.$deploy([]);
console.log('Contract deployed at', deployInfo.address);

const address = account.address;

console.log('Node balance', await aeSdk.getBalance(address));
console.log('Contract balance', (await contract.getBalance(address, { callStatic: false })).decodedResult);
console.log('Node balance', await aeSdk.getBalance(address));
console.log('Contract balance dry-run', (await contract.getBalance(address, { callStatic: true })).decodedResult);

outputs

Contract deployed at ct_9L62omp1ASfV9oRFNJSWEWNaRXhTAPyNr5CnxgBXjZyVNbVFh
Address ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E
Node balance 105447145675740744092
Contract balance 105446960420740744092n
Node balance 105446960933740744092
Contract balance dry-run 100000000000000105440960933740744092n

100000000000000105440960933740744092n needs to be 105440960933740744092n, 100000000000000000000000000000000000n is from here

amount: 100000000000000000000000000000000000n,

@davidyuk davidyuk added the bug Something isn't working label Aug 17, 2023
@davidyuk davidyuk added this to the next milestone Aug 17, 2023
@davidyuk davidyuk linked a pull request Aug 17, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant