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

servicefee: use an ordered map to make evaluation of expressions more deterministic #2

Open
zikani03 opened this issue Nov 11, 2024 · 3 comments

Comments

@zikani03
Copy link
Member

zikani03 commented Nov 11, 2024

The servicefee.FeeExpressions type is an alias of a map[string]float64 which means that it inherits the built in map's behavior which is especially apparent when iterating over the expressions to calculate a fee.

From: https://go.dev/ref/spec#For_range

The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next....

The effect is such that if you specify the fees as below, the service fee for the amount 10,000 for example can be either 500.0 OR 5.0 - we need this to be more deterministic, and have the rules evaluated in the order they are specified

	serviceFees := servicefee.NewFixedFee(servicefee.FeeExpressions{
		"x <= 5000":               200.00,
		"x >= 5000 && x <= 10000": 500.00,
		"x > 1000":                5.0,
	})

Try on Go Play Ground: https://go.dev/play/p/4FiMV6jd6cI

@Horac3
Copy link

Horac3 commented Nov 12, 2024

Can you add more context to the description?

@zikani03
Copy link
Member Author

@Horac3 i have updated the description. It would also be interesting to look into mutation testing for this, but that doesn't have to be part of the PR for this issue.

@Horac3
Copy link

Horac3 commented Nov 19, 2024

I should be able to push a PR anytime soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants