-
Notifications
You must be signed in to change notification settings - Fork 671
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
X-chain - introducing fees calculators #2700
base: master
Are you sure you want to change the base?
Changes from 138 commits
1adc328
f6d7382
3889e51
e725961
30a4343
add3a35
3d08216
8f35564
2b16538
4751e79
e00d7c9
b454987
f832034
62ab6d0
2241711
0318ea8
d33a6a2
d846cba
8a89505
3daec34
b1fdd62
a80ab15
a0020b1
1fb0662
c1fdd20
f28b80b
26fcb79
4d100eb
38f0386
ccb05f5
199424b
3b76de5
5ea9c0b
603fbec
8bc3da9
2b05cf1
0baba01
7512037
9b97764
1368b48
3046509
a4b81e6
392e935
78a1a5c
d3a733e
a362312
d251fe6
f735491
6a1af7c
fd8e512
33e3b70
507636e
399dfc8
089af5e
bf58efb
a78cd4d
3c52428
198c910
83caa3f
e34e3de
7feb04f
43169f4
7d7d1f7
2dd14a8
68a1f57
5992b33
d5ccb3b
dca34a5
8aaf991
cda811f
cd989f3
32da156
be7cf3e
d2525d5
c6dd66c
ae8231b
8270220
b7b0e0f
95d3ab5
7a17a9b
2906756
d3edbaa
3dbdd6b
e1e905c
737d429
b47ef55
af94f10
ee6bd99
6834a9e
cede533
3b04b63
d2772ec
6c7c6ec
50e75f9
b4d8ff4
6f36d2e
8cad1b3
b2e0b3e
bd2311e
a18bf63
6cd51ab
bfb4e56
d637d8b
e8a4c19
0cbf3cd
5130928
6282fa4
3af2422
f573101
4d668bd
5daa831
a1eadc0
212c379
f8afae3
1382841
b0d590e
dd00cc6
d5ffeda
69c942f
9e977df
bf03947
b9e1435
ce35df7
69bd78e
1ec2242
fa985ae
7ba37af
acda18a
f8019bd
a4631db
8e0d84f
c2d6e86
018988e
d890cbc
7f79fd1
5ffcc49
c0b2f50
3c69dba
e7958b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package fee | ||
|
||
import "github.com/ava-labs/avalanchego/vms/avm/txs" | ||
|
||
// Calculator is the interfaces that any fee Calculator must implement | ||
type Calculator interface { | ||
CalculateFee(tx *txs.Tx) (uint64, error) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package fee | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ava-labs/avalanchego/utils/units" | ||
"github.com/ava-labs/avalanchego/vms/avm/txs" | ||
) | ||
|
||
func TestTxFees(t *testing.T) { | ||
feeTestsDefaultCfg := StaticConfig{ | ||
TxFee: 1 * units.Avax, | ||
CreateAssetTxFee: 2 * units.Avax, | ||
} | ||
|
||
// chain times needed to have specific upgrades active | ||
eUpgradeTime := time.Unix(1713945427, 0) | ||
preEUpgradeTime := eUpgradeTime.Add(-1 * time.Second) | ||
|
||
tests := []struct { | ||
name string | ||
chainTime time.Time | ||
unsignedTx func() txs.UnsignedTx | ||
expected uint64 | ||
}{ | ||
{ | ||
name: "BaseTx pre EUpgrade", | ||
chainTime: preEUpgradeTime, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (No action required) Why is this parameter suggested for inclusion in the test case struct if it never varies? |
||
unsignedTx: baseTx, | ||
expected: feeTestsDefaultCfg.TxFee, | ||
}, | ||
{ | ||
name: "CreateAssetTx pre EUpgrade", | ||
chainTime: preEUpgradeTime, | ||
unsignedTx: createAssetTx, | ||
expected: feeTestsDefaultCfg.CreateAssetTxFee, | ||
}, | ||
{ | ||
name: "OperationTx pre EUpgrade", | ||
chainTime: preEUpgradeTime, | ||
unsignedTx: operationTx, | ||
expected: feeTestsDefaultCfg.TxFee, | ||
}, | ||
{ | ||
name: "ImportTx pre EUpgrade", | ||
chainTime: preEUpgradeTime, | ||
unsignedTx: importTx, | ||
expected: feeTestsDefaultCfg.TxFee, | ||
}, | ||
{ | ||
name: "ExportTx pre EUpgrade", | ||
chainTime: preEUpgradeTime, | ||
unsignedTx: exportTx, | ||
expected: feeTestsDefaultCfg.TxFee, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
uTx := tt.unsignedTx() | ||
fc := NewStaticCalculator(feeTestsDefaultCfg) | ||
haveFee, err := fc.CalculateFee(&txs.Tx{Unsigned: uTx}) | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expected, haveFee) | ||
}) | ||
} | ||
} | ||
|
||
func baseTx() txs.UnsignedTx { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (No action required) Maybe just inline these values given that they aren't used anywhere else? |
||
return &txs.BaseTx{} | ||
} | ||
|
||
func createAssetTx() txs.UnsignedTx { | ||
return &txs.CreateAssetTx{} | ||
} | ||
|
||
func operationTx() txs.UnsignedTx { | ||
return &txs.OperationTx{} | ||
} | ||
|
||
func importTx() txs.UnsignedTx { | ||
return &txs.ImportTx{} | ||
} | ||
|
||
func exportTx() txs.UnsignedTx { | ||
return &txs.ExportTx{} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(No action required) Should this be
static_calculator_test.go
?