test: integration test that verifies gas limits for Rust contract

This commit is contained in:
ppedziwiatr
2022-03-04 16:11:08 +01:00
committed by Piotr Pędziwiatr
parent 9de5d90345
commit 7fe41f6516
2 changed files with 17 additions and 5 deletions

View File

@@ -209,4 +209,20 @@ describe('Testing the Rust WASM Profit Sharing Token', () => {
expect(result.type).toEqual("error");
expect(result.errorMessage).toEqual("[CE:TransferAmountMustBeHigherThanZero]");
});
it('should honor gas limits', async () => {
pst.setEvaluationOptions({
gasLimit: 9000000
})
const result = await pst.dryWrite({
function: 'transfer',
target: 'uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M',
qty: 555
});
expect(result.type).toEqual("exception");
expect(result.errorMessage).toEqual("[RE:OOG] Out of gas! Used: 9000868, limit: 9000000");
});
});

View File

@@ -90,14 +90,10 @@ export class SmartWeaveGlobal {
this.gasUsed += gas;
if (this.gasUsed > this.gasLimit) {
throw new Error(
`[RE:OOG] Out of gas! Limit: ${this.formatGas(this.gasUsed)}, used: ${this.formatGas(this.gasLimit)}`
`[RE:OOG] Out of gas! Used: ${this.gasUsed}, limit: ${this.gasLimit}`
);
}
}
private formatGas(gas) {
return gas * 1e-4;
}
}
// tslint:disable-next-line: max-classes-per-file