You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm validating the transaction fees to ensure they aren't above a specific threshold. I'm using test invoke to validate most of my contract features. It works, except when it comes to network fees. The values are always 0 (during test invoke).
Is this expected? Is there any way that I can get the proper value of the net fee inside a smart contract?
There are some occasions where I have to attach an extra network fee. I remember this being fixed. Could anyone confirm? Do I need to use another endpoint to calculate this dynamic fee?
(Unrelated) When should I use int64 instead of int? I just realized I've been using int everywhere. Could this cause an overflow? Should I replace all int with int64?
Context
This is my contract code:
funcValidateFeeRequirement(feeReqFeeRequirement, ctxValidationContext) ValidationResult {
transaction:=runtime.GetScriptContainer()
iftransaction.NetFee>feeReq.MaxNetworkFee {
returnValidationResult{Success: false, ErrorMessage: "Network fee exceeds the maximum allowed fee"}
}
iftransaction.SysFee>feeReq.MaxSystemFee {
returnValidationResult{Success: false, ErrorMessage: "System fee exceeds the maximum allowed fee"}
}
returnValidationResult{Success: true}
}
It seems that NetFee is always 0. The following test won't work unless I change the net fee requirement to '-1'. This is an indicator that the current netfee of the test invoke is 0:
test("Validate fee requirement with network fee exceeding maximum",async()=>{constfeeRequirement=newFeeRequirement({maxNetworkFee: BigInt(0),// Will work if replaced with -1. maxSystemFee: BigInt(1000000)});constvalidationContext=createDummyValidationContext();const{result, exception}=awaitPermissionsManager.Test.validateFeeRequirement({feeReq: feeRequirement,ctx: validationContext});expect(exception).toBeNull();expect(result?.success).toBe(false);expect(result?.errorMessage).toBe('Network fee exceeds the maximum allowed fee');});
Is it possible to 'emulate' the network fees during a test invoke?
The text was updated successfully, but these errors were encountered:
lock9
changed the title
How to get the network fee during a test invoke? (inside a smart contract
How to get the network fee during a test invoke? (inside a smart contract)
Dec 26, 2024
Is there any way that I can get the proper value of the net fee inside a smart contract?
No. There is no "proper" value, especially when we're doing test invocations. There is no transaction to evaluate its size, it's not yet signed to evaluate GAS required for witness check. And users can legitimately add any amounts to the minimum allowed values.
When should I use int64 instead of int? I just realized I've been using int everywhere. Could this cause an overflow? Should I replace all int with int64?
With the compiler we have now they're all the same 256-bit integers.
Not sure if I understood how they are related, but I suppose it's about differences between testinvoke and a real invoke? Is it related to the dynamic fee calculation?
Uh oh!
There was an error while loading. Please reload this page.
Problem
I'm validating the transaction fees to ensure they aren't above a specific threshold. I'm using test invoke to validate most of my contract features. It works, except when it comes to network fees. The values are always 0 (during test invoke).
Context
This is my contract code:
It seems that NetFee is always 0. The following test won't work unless I change the net fee requirement to '-1'. This is an indicator that the current netfee of the test invoke is 0:
Is it possible to 'emulate' the network fees during a test invoke?
The text was updated successfully, but these errors were encountered: