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

fixbug can't calculate gas when program start with label #547

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/runtime/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export function opcodeFromSentence (words: string[], counter: number, interprete
if (opCodeMap[tealVersion][opCode.slice(0, opCode.length - 1)] !== undefined) {
throw new RuntimeError(RUNTIME_ERRORS.TEAL.INVALID_LABEL, { line: counter }); // eg. `int:` is invalid label as `int` is an opcode
}
interpreter.lineToCost[counter] = 0;
return new Label([opCode], counter);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/runtime/test/fixtures/basic-teal/assets/clear.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma version 5
// default clear program
int 1
return
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma version 5

txn ApplicationID
bz creation

loop:
load 0
int 10
<
bz break

load 0
int 1
+
store 0

b loop

break:

int 1
return

creation:
int 1
return
47 changes: 47 additions & 0 deletions packages/runtime/test/integration/gas-calculator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { types as rtypes } from '@algo-builder/runtime';
import { types } from "@algo-builder/web";
import { expect } from "chai";

import { AccountStore, Runtime } from "../../src/index";
import { AppDeploymentFlags } from "../../src/types";
import { useFixture } from "../helpers/integration";

describe("TEALv5: Pooled Opcode Cost calculation", function () {
useFixture("basic-teal");
const john = new AccountStore(10e6);

let runtime: Runtime;
let approvalProgramFileName: string;
let clearProgramFileName: string;
let flags: AppDeploymentFlags;
let appID: number;
let appCallParam: types.AppCallsParam;
this.beforeAll(async function () {
runtime = new Runtime([john]); // setup test
approvalProgramFileName = 'label-first-line.teal';
clearProgramFileName = 'clear.teal';

flags = {
sender: john.account,
globalBytes: 1,
globalInts: 1,
localBytes: 1,
localInts: 1
};

appID = runtime.deployApp(approvalProgramFileName, clearProgramFileName, flags, {}).appID;

appCallParam = {
type: types.TransactionType.CallApp,
sign: types.SignType.SecretKey,
fromAccount: john.account,
appID: appID,
payFlags: { totalFee: 1000 }
};
});

it("Gas should be number", function () {
const receipt = runtime.executeTx(appCallParam) as rtypes.TxReceipt;
expect(receipt.gas).to.equal(98);
});
});