Giter Club home page Giter Club logo

Comments (29)

gl-pgege avatar gl-pgege commented on July 18, 2024 1

That fixed it! Thanks for all the help!

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

Hi @pgege , i tried deploying using

runtime.executeTx({
      type: TransactionType.DeploySSC,
      sign: SignType.SecretKey,
      fromAccount: john.account,
      approvalProgram: approvalProgram,
      clearProgram: clearProgram,
      globalBytes: 5,
      globalInts: 4,
      localBytes: 0,
      localInts: 0,
      appArgs: [
        "int:0",
        "int:25412621"
      ],
      payFlags: { totalFee: 1000 }
    });

asdf

you can also refer to

it("should execute group of (payment + app creation) successfully", () => {

i think probably this is happening because clearProgram is not passed.
are you using this in js project ? using ts project is really helpful, it shows type error instantly.

also, we will be adding more docs about parameters.

Please let me know if this solves your problem

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

I'm still facing the same problem, I went ahead to try out the example from the reference as well and it still wasn't deployed. I'm using the yarn installed version of algob by the way.

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

okay, version maybe the problem because support for this isn't included in 1.0.2 release, you can use yarn link to link with the latest code,

git clone https://github.com/scale-it/algo-builder.git
cd algo-builder
yarn install
yarn build
cd packages/algob
yarn link

are you using algob like this ?

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

Hi, Thanks I was able to deploy the app once I used the latest code. However I've run into another problem. When I attempt to call the deployed application i get the following error:

RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to access memory outside buffer bounds
      at boundsError (internal/buffer.js:81:11)
      at Buffer.readBigUInt64BE (internal/buffer.js:114:5)
      at Btoi.execute (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/interpreter/opcode-list.js:882:43)
      at Interpreter.execute (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/interpreter/interpreter.js:147:25)
      at Runtime.run (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/runtime.js:496:21)
      at /home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:387:34
      at Array.forEach (<anonymous>)
      at Ctx.processTransactions (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:366:19)
      at Runtime.executeTx (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/runtime.js:482:18)
      at Context.<anonymous> (test/sample-test.js:186:13)
      at processImmediate (internal/timers.js:462:21)

Here is the transaction I have attempted to execute contracEntryTx is the transaction:

    const createContractTxGroup = [
      {
        type: types.TransactionType.DeploySSC,
        sign: types.SignType.SecretKey,
        fromAccount: contract_owner.account,
        approvalProgram: approvalProgram,
        clearProgram: clearProgram,
        localInts: 0,
        localBytes: 0,
        globalInts: 4,
        globalBytes: 5,
        appArgs: [
          "int:0",
          "int:25412621"
        ],
        payFlags: { totalFee: validTxFee }
      },
      {
        type: types.TransactionType.TransferAlgo,
        sign: types.SignType.SecretKey,
        fromAccount: contract_owner.account,
        toAccountAddr: escrow.address,
        amountMicroAlgos: contractFunds,
        payFlags: { totalFee: validTxFee }
      }
    ];

    runtime.executeTx(createContractTxGroup);

    syncAccounts();

    const iterator = runtime.store.globalApps.keys();
    const appId = iterator.next().value;

    const appArgs = [stringToBytes('submit'), stringToBytes('50')]

    const appAccounts = [
      developer.address,
      escrow.address
    ]

    const contractEntryTx = {
      type: types.TransactionType.CallNoOpSSC,
      sign: types.SignType.SecretKey,
      fromAccount: contract_owner.account,
      appId,
      payFlags: {totalFee: validTxFee},
      appArgs,
      accounts: appAccounts
    }

    runtime.executeTx(contractEntryTx);

Here's a snippet of the code for the stateful smart contract being deployed (I have included the code that is executed on submission to the contract.


    ESCROW_ACCOUNT = 2
    DEVELOPER_ACCOUNT = 1

    # ensuring the account is funded with minimum amount of funds specified before allowing submissions
    is_account_funded = Balance(Int(ESCROW_ACCOUNT)) >= Int(withdraw_amount)
    
    on_submit = Seq([
        Assert(
            is_creator
        ),
        Assert(
            Global.round() >= Btoi(App.globalGet(Bytes("SubmissionBegin")))
        ),
        Assert(
            Global.round() <= Btoi(App.globalGet(Bytes("SubmissionEnd")))
        ),
        If(Btoi(Txn.application_args[1]) > Btoi(App.globalGet(Bytes("LeaderScore"))), 
            Return(Int(0))
        ),
        App.globalPut(Bytes("LeaderAddress"), Txn.accounts[DEVELOPER_ACCOUNT]),
        App.globalPut(Bytes("LeaderScore"), Txn.application_args[1]),
        Return(is_account_funded)
    ])

If you can assist with this that would be great. Thanks!

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

Hi

Assert(
            Global.round() >= Btoi(App.globalGet(Bytes("SubmissionBegin")))
        ),
        Assert(
            Global.round() <= Btoi(App.globalGet(Bytes("SubmissionEnd")))
        ),

i need some more detail about this, are these values stored as Bytes while creating application ?
or as integers as in this case
App.globalPut(Bytes("SubmissionEnd"), Btoi(Txn.application_args[1]))

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

oh, got it, error is coming from here stringToBytes('50') you need to convert from integer to bytes instead of string.

also, we have added debug trace, you can check the values being pushed into stack at each step. it is very useful for debugging
https://github.com/scale-it/algo-builder/blob/master/docs/guide/testing-teal.md#debugging

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

This is an example goal command which is why I used the stringToBytes('50').

./goal app call --app-id 1 --from [contract_owner_address] --app-arg "str:submit" --app-arg "str:50" --app-account [developer_address] --app-account [escrow_address]

I have tried the following as well but still get the same error: parseSSCAppArgs(['str:submit','str:50'])

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

The smart contract/app essentially takes the number passed along with 'str:50' and compares it with the current score. If the passed argument value, 50 in this case is less than the currently stored score. Then the newly passed argument/value is stored along with the address passed with the call to the app.

This is the PyTeal code where the passed argument 'str:50' is being stored:

App.globalPut(Bytes("LeaderScore"), Txn.application_args[1])

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

okay, it think we should pass it as int:50. because we are converting a integer into bytes and then back to integer from bytes.

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

let me check if passing str:50 works on algorand node, probably it will give some other value or throw error.

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

This is how the value is stored in the global state on my algorand node.

"LeaderScore": {
    "tb": "25",
    "tt": 1
  },

str:50 works as an app-arg on my algorand node.

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

Okay, thanks. looking into it

from algo-builder.

robert-zaremba avatar robert-zaremba commented on July 18, 2024

We suspect that there is some rubbish number trying to convert to integer. Let's by creating TEAL code with 2 branches:

  1. Set the value using str:50 to "mynumber" global.
  2. Read the value using Btoi(...) and compare it to a hardcoded integer in TEAL:
    Assert(
        Int(50) == Btoi(App.globalGet(Bytes("mynumber")))
    )
    

And run it in both our runtime and the go-algorand node.

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

Hi
Checked on algorand node, Btoi("str:50") indeed gives some garbage value, which is greater than Int(50) that's why the code passes,

  • only fails if compared exact values (==) instead of (>), code will fail

https://github.com/scale-it/algo-builder/tree/test-example/examples/check

equal

from algo-builder.

robert-zaremba avatar robert-zaremba commented on July 18, 2024

Algo Builder helped to detect nasty bug / misuse 👍

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

Thanks a lot guys! It works now. I changed my contract to accept "int:50" instead.

I have one final step in my test suite which is to test withdrawing the funds. Here is my code:

// setup escrow account
    const escrowProg = getProgram('escrow_contract.py');
    const lsig = runtime.getLogicSig(escrowProg, []);
    const escrowAddress = lsig.address();

    // sync escrow account
    escrow = runtime.getAccount(escrowAddress);
    console.log('Escrow Address: ', escrowAddress);

    // create application
    const createContractTxGroup = [
      {
        type: types.TransactionType.DeploySSC,
        sign: types.SignType.SecretKey,
        fromAccount: contract_owner.account,
        approvalProgram: approvalProgram,
        clearProgram: clearProgram,
        localInts: 0,
        localBytes: 0,
        globalInts: 4,
        globalBytes: 5,
        appArgs: [
          "int:0",
          "int:25412621"
        ],
        payFlags: { totalFee: validTxFee }
      },
      {
        type: types.TransactionType.TransferAlgo,
        sign: types.SignType.SecretKey,
        fromAccount: contract_owner.account,
        toAccountAddr: escrowAddress,
        amountMicroAlgos: contractFunds,
        payFlags: { totalFee: validTxFee }
      }
    ];

    runtime.executeTx(createContractTxGroup);

    syncAccounts();

    const iterator = runtime.store.globalApps.keys();
    const appId = iterator.next().value;

    const appAccounts = [
      developer.address,
      escrow.address
    ]

    const contractEntryTx = {
      type: types.TransactionType.CallNoOpSSC,
      sign: types.SignType.SecretKey,
      fromAccount: contract_owner.account,
      appId,
      payFlags: {totalFee: validTxFee},
      appArgs: ['str:submit','int:50'],
      accounts: appAccounts
    }

    runtime.executeTx(contractEntryTx);
    
    syncAccounts();

    appArgs = [stringToBytes('deposit')];
    txGroup = [
      {
        type: types.TransactionType.CallNoOpSSC,
        sign: types.SignType.SecretKey,
        fromAccount: developer.account,
        appId,
        payFlags: { totalFee: 1000 },
        appArgs: appArgs
      },
      {
        type: types.TransactionType.TransferAlgo,
        sign: types.SignType.LogicSignature,
        fromAccountAddr: escrow.account.addr,
        toAccountAddr: developer.address,
        amountMicroAlgos: 0,
        lsig: lsig,
        payFlags: { totalFee: 1000, closeRemainderTo: developer.address }
      }
    ];
    
    runtime.executeTx(txGroup);

When I execute the last transaction (txGroup) to withdraw, I get the following error:

Error: RUNTIME_ERR1401: Cannot withdraw 1000 microalgos from account EO7DEARIDKG2C4LXX2KI2UGACPGAKDW5SK5EJJQ24HCCYT3BASEWUHJZHI: resulting balance would be insufficient

I used the crowdfunding example as a reference, I would expect the closeRemainderTo to prevent this from happening. Is there something I'm doing wrong?

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

Hi
this error occurs when resulting account balance after transaction is less than min Balance, minimum balance increases when account is opted-in(to ASA or SSC) or created asa or ssc,
Possible cases:

  1. does developer.account has enough balance to cover fees ?
  2. does escrow account has enough balance ?

when we use closeRemainderTo, it ensures, all the remaining balance is sent to closeRemainderTo address after transaction is completed, in this case i think transaction is failing before

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

The error occurs for the escrow account, I noticed something odd when I printed out the balances in the accounts.

Stateful smart contract withdrawal
developer account 50000000n
developer address SFTRLDTYSEOMVWVQNQFCMEHVOMKEZYYGP6EIJIFENDSQYXUGXLMT7QG7L4
escrow account 202000n
escrow address 44BF7PCMOGR2CEQTQYDWIXHTPSGMLBZODM5A66HCSV25ZQKBPNVJY2HULY
    1) should allow withdrawal for winner


  4 passing (547ms)
  1 failing

  1) Stateful smart contract withdrawal
       should allow withdrawal for winner:
     Error: RUNTIME_ERR1401: Cannot withdraw 272000 microalgos from account 44BF7PCMOGR2CEQTQYDWIXHTPSGMLBZODM5A66HCSV25ZQKBPNVJY2HULY: resulting balance would be insufficient
      at Ctx.assertMinBalance (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:24:19)
      at Ctx.deductFee (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:219:14)
      at /home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:368:18
      at Array.forEach (<anonymous>)
      at Ctx.processTransactions (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:366:19)
      at Runtime.executeTx (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/runtime.js:482:18)
      at Context.<anonymous> (test/sample-test.js:401:13)
      at processImmediate (internal/timers.js:462:21)

The error shows that 272000 is being withdrawn. However, it's a closeout command so the value truly should be 202000. I have checked the amount transferred to the escrow as well and it's 202000. I'm not sure where the extra 70000 being withdrawn comes from. Once again here is the transaction I am attempting to execute:

const withdrawFundsTxGroup = [
      {
        type: types.TransactionType.CallNoOpSSC,
        sign: types.SignType.SecretKey,
        fromAccount: contract_owner.account,
        appId,
        appArgs: [
          "str:deposit",
        ],
        payFlags: { totalFee: validTxFee }
      },
      {
        type: types.TransactionType.TransferAlgo,
        sign: types.SignType.LogicSignature,
        fromAccountAddr: escrow.account.addr,
        toAccountAddr: GLOBAL_ZERO_ADDRESS,
        amountMicroAlgos: 0,
        lsig: lsig,
        payFlags: {closeRemainderTo: developer.address}
      }
    ];

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

this is happening probably because you have not passed totalFee in payFlags, by default when transaction parameters are processed fee could be higher, as in this case.

does this solves this ?

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

When I add the totalFee in payFlags I run into this error that I pointed out earlier in this reply:

Thanks a lot guys! It works now. I changed my contract to accept "int:50" instead.

I have one final step in my test suite which is to test withdrawing the funds. Here is my code:

// setup escrow account
    const escrowProg = getProgram('escrow_contract.py');
    const lsig = runtime.getLogicSig(escrowProg, []);
    const escrowAddress = lsig.address();

    // sync escrow account
    escrow = runtime.getAccount(escrowAddress);
    console.log('Escrow Address: ', escrowAddress);

    // create application
    const createContractTxGroup = [
      {
        type: types.TransactionType.DeploySSC,
        sign: types.SignType.SecretKey,
        fromAccount: contract_owner.account,
        approvalProgram: approvalProgram,
        clearProgram: clearProgram,
        localInts: 0,
        localBytes: 0,
        globalInts: 4,
        globalBytes: 5,
        appArgs: [
          "int:0",
          "int:25412621"
        ],
        payFlags: { totalFee: validTxFee }
      },
      {
        type: types.TransactionType.TransferAlgo,
        sign: types.SignType.SecretKey,
        fromAccount: contract_owner.account,
        toAccountAddr: escrowAddress,
        amountMicroAlgos: contractFunds,
        payFlags: { totalFee: validTxFee }
      }
    ];

    runtime.executeTx(createContractTxGroup);

    syncAccounts();

    const iterator = runtime.store.globalApps.keys();
    const appId = iterator.next().value;

    const appAccounts = [
      developer.address,
      escrow.address
    ]

    const contractEntryTx = {
      type: types.TransactionType.CallNoOpSSC,
      sign: types.SignType.SecretKey,
      fromAccount: contract_owner.account,
      appId,
      payFlags: {totalFee: validTxFee},
      appArgs: ['str:submit','int:50'],
      accounts: appAccounts
    }

    runtime.executeTx(contractEntryTx);
    
    syncAccounts();

    appArgs = [stringToBytes('deposit')];
    txGroup = [
      {
        type: types.TransactionType.CallNoOpSSC,
        sign: types.SignType.SecretKey,
        fromAccount: developer.account,
        appId,
        payFlags: { totalFee: 1000 },
        appArgs: appArgs
      },
      {
        type: types.TransactionType.TransferAlgo,
        sign: types.SignType.LogicSignature,
        fromAccountAddr: escrow.account.addr,
        toAccountAddr: developer.address,
        amountMicroAlgos: 0,
        lsig: lsig,
        payFlags: { totalFee: 1000, closeRemainderTo: developer.address }
      }
    ];
    
    runtime.executeTx(txGroup);

When I execute the last transaction (txGroup) to withdraw, I get the following error:

Error: RUNTIME_ERR1401: Cannot withdraw 1000 microalgos from account EO7DEARIDKG2C4LXX2KI2UGACPGAKDW5SK5EJJQ24HCCYT3BASEWUHJZHI: resulting balance would be insufficient

I used the crowdfunding example as a reference, I would expect the closeRemainderTo to prevent this from happening. Is there something I'm doing wrong?

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

okay, i am not able to recreate this issue, we have test for it

it("should correctly close escrow account if closeRemainderTo is passed", function () {

let me try one more thing

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

this error probably occurs while deducting fee, tried a test with group tx also, not able to recreate

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024
The error shows that 272000 is being withdrawn. However, it's a closeout command so the value truly should be 202000. I have checked the amount transferred to the escrow as well and it's 202000. I'm not sure where the extra 70000 being withdrawn comes from. Once again here is the transaction I am attempting to execute:

could you check these logs after passing totalFee ?

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

I tried adding it, here is my code:

    const withdrawFundsTxGroup = [
      {
        type: types.TransactionType.CallNoOpSSC,
        sign: types.SignType.SecretKey,
        fromAccount: contract_owner.account,
        appId,
        appArgs: [
          "str:deposit",
        ],
        payFlags: { totalFee: validTxFee }
      },
      {
        type: types.TransactionType.TransferAlgo,
        sign: types.SignType.LogicSignature,
        fromAccountAddr: escrow.account.addr,
        toAccountAddr: GLOBAL_ZERO_ADDRESS,
        amountMicroAlgos: 0,
        lsig: lsig,
        payFlags: {totalFee:1000, closeRemainderTo: developer.address}
      }
    ];

However I get the following error:

Error: RUNTIME_ERR1401: Cannot withdraw 1000 microalgos from account YRH6HL54QZUVWJNN4TQCIMTCMTRPAM6SFBPLDMWCMQAI3SBQQICSNXLVRQ: resulting balance would be insufficient
      at Ctx.assertMinBalance (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:24:19)
      at Ctx.deductFee (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:219:14)
      at /home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:368:18
      at Array.forEach (<anonymous>)
      at Ctx.processTransactions (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:366:19)
      at Runtime.executeTx (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/runtime.js:482:18)
      at Context.<anonymous> (test/sample-test.js:401:13)
      at processImmediate (internal/timers.js:462:21)

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

in this case what is the balance of address in the error ?

from algo-builder.

gl-pgege avatar gl-pgege commented on July 18, 2024

It's the escrow account and it has 202000 as well. Here's a log of the accounts:

developer account 50000000n
developer address X7OG5HNSPK2777NNWXFRC2TNTIYVZYOY5VU7MDLNJYTXCZ5EGXSOR6TRC4
escrow account 202000n
escrow address YRH6HL54QZUVWJNN4TQCIMTCMTRPAM6SFBPLDMWCMQAI3SBQQICSNXLVRQ
    1) should allow withdrawal for winner


  4 passing (640ms)
  1 failing

  1) Stateful smart contract withdrawal
       should allow withdrawal for winner:
     Error: RUNTIME_ERR1401: Cannot withdraw 1000 microalgos from account YRH6HL54QZUVWJNN4TQCIMTCMTRPAM6SFBPLDMWCMQAI3SBQQICSNXLVRQ: resulting balance would be insufficient
      at Ctx.assertMinBalance (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:24:19)
      at Ctx.deductFee (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:219:14)
      at /home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:368:18
      at Array.forEach (<anonymous>)
      at Ctx.processTransactions (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/ctx.js:366:19)
      at Runtime.executeTx (/home/paul/Desktop/algo_proj/algo-builder/packages/runtime/build/runtime.js:482:18)
      at Context.<anonymous> (test/sample-test.js:401:13)
      at processImmediate (internal/timers.js:462:21)

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

okay, got it, i think you are using previous version of algob,
this is happening because of algorand min_balance.

In previous version min balance is = 1e6 that's why the code is failing

e93f75f
we have updated the min balance in this PR by taking reference from here https://github.com/algorand/go-algorand/blob/02eacd13d55251c854042a12eca8dc066d840e8c/config/consensus.go#L672 (Updated new min balance is 0.1e6)

from algo-builder.

amityadav0 avatar amityadav0 commented on July 18, 2024

so to fix this you will have to increase the escrow balance because to perform any transaction before closing, the min balance condition must be satisfied

from algo-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.