test: integration test that verifies gas limits for Rust contract
This commit is contained in:
committed by
Piotr Pędziwiatr
parent
9de5d90345
commit
7fe41f6516
@@ -209,4 +209,20 @@ describe('Testing the Rust WASM Profit Sharing Token', () => {
|
|||||||
expect(result.type).toEqual("error");
|
expect(result.type).toEqual("error");
|
||||||
expect(result.errorMessage).toEqual("[CE:TransferAmountMustBeHigherThanZero]");
|
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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -90,14 +90,10 @@ export class SmartWeaveGlobal {
|
|||||||
this.gasUsed += gas;
|
this.gasUsed += gas;
|
||||||
if (this.gasUsed > this.gasLimit) {
|
if (this.gasUsed > this.gasLimit) {
|
||||||
throw new Error(
|
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
|
// tslint:disable-next-line: max-classes-per-file
|
||||||
|
|||||||
Reference in New Issue
Block a user