Comments (29)
That fixed it! Thanks for all the help!
from algo-builder.
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 }
});
you can also refer to
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.
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.
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.
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.
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.
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.
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.
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.
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.
let me check if passing str:50
works on algorand node, probably it will give some other value or throw error.
from algo-builder.
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.
Okay, thanks. looking into it
from algo-builder.
We suspect that there is some rubbish number trying to convert to integer. Let's by creating TEAL code with 2 branches:
- Set the value using
str:50
to"mynumber"
global. - 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.
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
from algo-builder.
Algo Builder helped to detect nasty bug / misuse 👍
from algo-builder.
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.
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:
- does developer.account has enough balance to cover fees ?
- 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.
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.
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.
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.
okay, i am not able to recreate this issue, we have test for it
let me try one more thing
from algo-builder.
this error probably occurs while deducting fee, tried a test with group tx also, not able to recreate
from algo-builder.
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.
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.
in this case what is the balance of address in the error ?
from algo-builder.
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.
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.
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)
- Add support `loadLogic` for *.teal program and SCParams HOT 3
- Contract to contract call HOT 2
- Unable to compile contracts on Windows machine HOT 11
- Mocha printing "ASA file not defined" HOT 2
- Rename optIntoASA to optInToASA HOT 2
- Getting warning for opt out of asset transaction in Mocha
- Allow `getProgram` to compile files outside of assets directory HOT 4
- Txn.asset_sender() gives different values in runtime and TestNet HOT 4
- RUNTIME_ERR1003: Type of data is incorrect. Expected unsigned integer (upto 64 bit) but got 0 HOT 7
- ABI support HOT 3
- TEAL 7 makes runtime fail HOT 4
- Improve runtime debug output for contract-to-contract calls
- Minimal interactive debugger for runtime HOT 1
- Overwritting parameter from algobuilder script to Pyteal programe with deployer.mkDelegatedLsig HOT 3
- [Yarn workspaces config] Cannot find module '@algo-builder/web' or its corresponding type declarations. HOT 4
- Error: RUNTIME_ERR1500: Invalid ASA definition: Total must be a positive number and smaller than 2^64-1 HOT 2
- Algob deploy not working HOT 7
- InnerTxn does not have 'foreignAssets' field HOT 1
- Invalid value "" for config.networks.testnet.token - Expected a value of type string (with length > 10). HOT 2
- Cannot find module 'findup-sync' in runtime package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algo-builder.