forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
152 additions
and
9 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
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,129 @@ | ||
package legacypool | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
func Test_celoContextImpl_CompareFees(t *testing.T) { | ||
currA := common.HexToAddress("0xA") | ||
currB := common.HexToAddress("0xB") | ||
|
||
exchangeRates := ExchangeRates{ | ||
currA: big.NewRat(1, 2), // token is worth 2 celo | ||
currB: big.NewRat(2, 1), // token is worth 0.5 celo | ||
} | ||
type args struct { | ||
val1 *big.Int | ||
feeCurrency1 *common.Address | ||
val2 *big.Int | ||
feeCurrency2 *common.Address | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want int | ||
}{ | ||
// Native currency | ||
{ | ||
name: "Same amount of native currency", | ||
args: args{ | ||
val1: big.NewInt(1), | ||
feeCurrency1: nil, | ||
val2: big.NewInt(1), | ||
feeCurrency2: nil, | ||
}, | ||
want: 0, | ||
}, { | ||
name: "Different amounts of native currency 1", | ||
args: args{ | ||
val1: big.NewInt(2), | ||
feeCurrency1: nil, | ||
val2: big.NewInt(1), | ||
feeCurrency2: nil, | ||
}, | ||
want: 1, | ||
}, { | ||
name: "Different amounts of native currency 2", | ||
args: args{ | ||
val1: big.NewInt(1), | ||
feeCurrency1: nil, | ||
val2: big.NewInt(5), | ||
feeCurrency2: nil, | ||
}, | ||
want: -1, | ||
}, | ||
// Mixed currency | ||
{ | ||
name: "Same amount of mixed currency", | ||
args: args{ | ||
val1: big.NewInt(1), | ||
feeCurrency1: nil, | ||
val2: big.NewInt(1), | ||
feeCurrency2: &currA, | ||
}, | ||
want: -1, | ||
}, { | ||
name: "Different amounts of mixed currency 1", | ||
args: args{ | ||
val1: big.NewInt(2), | ||
feeCurrency1: nil, | ||
val2: big.NewInt(1), | ||
feeCurrency2: &currA, | ||
}, | ||
want: 0, | ||
}, { | ||
name: "Different amounts of mixed currency 2", | ||
args: args{ | ||
val1: big.NewInt(1), | ||
feeCurrency1: nil, | ||
val2: big.NewInt(2), | ||
feeCurrency2: &currB, | ||
}, | ||
want: 0, | ||
}, | ||
// Two fee currencies | ||
{ | ||
name: "Same amount of same currency", | ||
args: args{ | ||
val1: big.NewInt(1), | ||
feeCurrency1: &currA, | ||
val2: big.NewInt(1), | ||
feeCurrency2: &currA, | ||
}, | ||
want: 0, | ||
}, { | ||
name: "Different amounts of same currency 1", | ||
args: args{ | ||
val1: big.NewInt(3), | ||
feeCurrency1: &currA, | ||
val2: big.NewInt(1), | ||
feeCurrency2: &currA, | ||
}, | ||
want: 1, | ||
}, { | ||
name: "Different amounts of same currency 2", | ||
args: args{ | ||
val1: big.NewInt(1), | ||
feeCurrency1: &currA, | ||
val2: big.NewInt(7), | ||
feeCurrency2: &currA, | ||
}, | ||
want: -1, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cc := &celoContextImpl{ | ||
backend: nil, | ||
registry: nil, | ||
exchangeRates: exchangeRates, | ||
} | ||
if got := cc.CompareValue(tt.args.val1, tt.args.feeCurrency1, tt.args.val2, tt.args.feeCurrency2); got != tt.want { | ||
t.Errorf("celoContextImpl.CompareFees() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |