-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ORA1289 Test delegators cant easily game the system (#302)
Test some of the ways that delegators might be able to game the system, and ensure that they are not possible. --------- Co-authored-by: T <relyt29@users.noreply.github.com> Co-authored-by: Kenny P <17100641+kpeluso@users.noreply.github.com> Co-authored-by: Kenny <pelusoken@gmail.com>
- Loading branch information
1 parent
b3a3c7e
commit 370d61c
Showing
5 changed files
with
397 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package testutil | ||
|
||
import ( | ||
"testing" | ||
|
||
alloraMath "github.com/allora-network/allora-chain/math" | ||
require "github.com/stretchr/testify/require" | ||
) | ||
|
||
func InEpsilon(t *testing.T, value alloraMath.Dec, target string, epsilon string) { | ||
epsilonDec := alloraMath.MustNewDecFromString(epsilon) | ||
targetDec := alloraMath.MustNewDecFromString(target) | ||
one := alloraMath.MustNewDecFromString("1") | ||
|
||
lowerMultiplier, err := one.Sub(epsilonDec) | ||
require.NoError(t, err) | ||
lowerBound, err := targetDec.Mul(lowerMultiplier) | ||
require.NoError(t, err) | ||
|
||
upperMultiplier, err := one.Add(epsilonDec) | ||
require.NoError(t, err) | ||
upperBound, err := targetDec.Mul(upperMultiplier) | ||
require.NoError(t, err) | ||
|
||
if lowerBound.Lt(upperBound) { // positive values, lower < value < upper | ||
require.True(t, value.Gte(lowerBound), "value: %s, lowerBound: %s", value.String(), lowerBound.String()) | ||
require.True(t, value.Lte(upperBound), "value: %s, upperBound: %s", value.String(), upperBound.String()) | ||
} else { // negative values, upper < value < lower | ||
require.True(t, value.Lte(lowerBound), "value: %s, lowerBound: %s", value.String(), lowerBound.String()) | ||
require.True(t, value.Gte(upperBound), "value: %s, upperBound: %s", value.String(), upperBound.String()) | ||
} | ||
} | ||
|
||
func InEpsilon2(t *testing.T, value alloraMath.Dec, target string) { | ||
InEpsilon(t, value, target, "0.01") | ||
} | ||
|
||
func InEpsilon3(t *testing.T, value alloraMath.Dec, target string) { | ||
InEpsilon(t, value, target, "0.001") | ||
} | ||
|
||
/*unused | ||
func InEpsilon4(t *testing.T, value alloraMath.Dec, target string) { | ||
s.inEpsilon(t, value, target, "0.0001") | ||
}*/ | ||
|
||
func InEpsilon5(t *testing.T, value alloraMath.Dec, target string) { | ||
InEpsilon(t, value, target, "0.00001") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.