"testing"
"time"
- "github.com/bytom/blockchain/signers"
- "github.com/bytom/blockchain/txbuilder"
- "github.com/bytom/consensus"
- "github.com/bytom/crypto/ed25519/chainkd"
- "github.com/bytom/protocol/bc"
- "github.com/bytom/testutil"
+ "github.com/bytom/bytom/blockchain/signers"
+ "github.com/bytom/bytom/blockchain/txbuilder"
+ "github.com/bytom/bytom/consensus"
+ "github.com/bytom/bytom/crypto/ed25519/chainkd"
+ "github.com/bytom/bytom/protocol/bc"
+ "github.com/bytom/bytom/testutil"
)
func TestReserveBtmUtxoChain(t *testing.T) {
- chainTxUtxoNum = 3
+ txbuilder.ChainTxUtxoNum = 3
utxos := []*UTXO{}
m := mockAccountManager(t)
for i := uint64(1); i <= 20; i++ {
OutputID: bc.Hash{V0: i},
AccountID: "TestAccountID",
AssetID: *consensus.BTMAssetID,
- Amount: i * chainTxMergeGas,
+ Amount: i * txbuilder.ChainTxMergeGas,
}
utxos = append(utxos, utxo)
err bool
}{
{
- amount: 1 * chainTxMergeGas,
+ amount: 1 * txbuilder.ChainTxMergeGas,
want: []uint64{1},
},
{
- amount: 888888 * chainTxMergeGas,
+ amount: 888888 * txbuilder.ChainTxMergeGas,
want: []uint64{},
err: true,
},
{
- amount: 7 * chainTxMergeGas,
+ amount: 7 * txbuilder.ChainTxMergeGas,
want: []uint64{4, 3, 1},
},
{
- amount: 15 * chainTxMergeGas,
+ amount: 15 * txbuilder.ChainTxMergeGas,
want: []uint64{5, 4, 3, 2, 1, 6},
},
{
- amount: 163 * chainTxMergeGas,
+ amount: 163 * txbuilder.ChainTxMergeGas,
want: []uint64{20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 2, 1, 3},
},
}
got := []uint64{}
for _, utxo := range utxos {
- got = append(got, utxo.Amount/chainTxMergeGas)
+ got = append(got, utxo.Amount/txbuilder.ChainTxMergeGas)
}
if !testutil.DeepEqual(got, c.want) {
}
func TestBuildBtmTxChain(t *testing.T) {
- chainTxUtxoNum = 3
+ txbuilder.ChainTxUtxoNum = 3
m := mockAccountManager(t)
cases := []struct {
inputUtxo []uint64
inputUtxo: []uint64{5},
wantInput: [][]uint64{},
wantOutput: [][]uint64{},
- wantUtxo: 5 * chainTxMergeGas,
+ wantUtxo: 5 * txbuilder.ChainTxMergeGas,
},
{
inputUtxo: []uint64{5, 4},
wantOutput: [][]uint64{
[]uint64{8},
},
- wantUtxo: 8 * chainTxMergeGas,
+ wantUtxo: 8 * txbuilder.ChainTxMergeGas,
},
{
inputUtxo: []uint64{5, 4, 1, 1},
[]uint64{9},
[]uint64{9},
},
- wantUtxo: 9 * chainTxMergeGas,
+ wantUtxo: 9 * txbuilder.ChainTxMergeGas,
},
{
inputUtxo: []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24},
[]uint64{3038},
[]uint64{3491},
},
- wantUtxo: 3491 * chainTxMergeGas,
+ wantUtxo: 3491 * txbuilder.ChainTxMergeGas,
},
}
utxos := []*UTXO{}
for _, amount := range c.inputUtxo {
utxos = append(utxos, &UTXO{
- Amount: amount * chainTxMergeGas,
+ Amount: amount * txbuilder.ChainTxMergeGas,
AssetID: *consensus.BTMAssetID,
Address: acp.Address,
ControlProgram: acp.ControlProgram,
for i, tpl := range tpls {
gotInput := []uint64{}
for _, input := range tpl.Transaction.Inputs {
- gotInput = append(gotInput, input.Amount()/chainTxMergeGas)
+ gotInput = append(gotInput, input.Amount()/txbuilder.ChainTxMergeGas)
}
gotOutput := []uint64{}
for _, output := range tpl.Transaction.Outputs {
- gotOutput = append(gotOutput, output.Amount/chainTxMergeGas)
+ gotOutput = append(gotOutput, output.Amount/txbuilder.ChainTxMergeGas)
}
if !testutil.DeepEqual(c.wantInput[i], gotInput) {
}
func TestCalcMergeGas(t *testing.T) {
- chainTxUtxoNum = 10
+ txbuilder.ChainTxUtxoNum = 10
cases := []struct {
utxoNum int
gas uint64
},
{
utxoNum: 9,
- gas: chainTxMergeGas,
+ gas: txbuilder.ChainTxMergeGas,
},
{
utxoNum: 10,
- gas: chainTxMergeGas,
+ gas: txbuilder.ChainTxMergeGas,
},
{
utxoNum: 11,
- gas: chainTxMergeGas * 2,
+ gas: txbuilder.ChainTxMergeGas * 2,
},
{
utxoNum: 20,
- gas: chainTxMergeGas * 3,
+ gas: txbuilder.ChainTxMergeGas * 3,
},
{
utxoNum: 21,
- gas: chainTxMergeGas * 3,
+ gas: txbuilder.ChainTxMergeGas * 3,
},
{
utxoNum: 74,
- gas: chainTxMergeGas * 9,
+ gas: txbuilder.ChainTxMergeGas * 9,
},
}