Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jan 15, 2018
1 parent 8186007 commit 28a5e45
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 7 deletions.
18 changes: 12 additions & 6 deletions modules/transactionpool/consts.go
Expand Up @@ -28,12 +28,6 @@ const (
// default size during times of congestion.
TransactionPoolExponentiation = 3

// TransactionPoolSizeForFee defines how large the transaction pool needs to
// be before it starts expecting fees to be on the transaction. This initial
// limit is to help the network grow and provide some wiggle room for
// wallets that are not yet able to operate via a fee market.
TransactionPoolSizeForFee = 500e3

// TransactionPoolSizeTarget defines the target size of the pool when the
// transactions are paying 1 SC / kb in fees.
TransactionPoolSizeTarget = 3e6
Expand Down Expand Up @@ -71,6 +65,18 @@ var (
minEstimation = types.SiacoinPrecision.Div64(100).Div64(1e3)
)

var (
// TransactionPoolSizeForFee defines how large the transaction pool needs to
// be before it starts expecting fees to be on the transaction. This initial
// limit is to help the network grow and provide some wiggle room for
// wallets that are not yet able to operate via a fee market.
TransactionPoolSizeForFee = build.Select(build.Var{
Standard: int(500e3),
Dev: int(500e3),
Testing: int(30e3),
}).(int)
)

// Variables related to propagating transactions through the network.
var (
// relayTransactionSetTimeout establishes the timeout for a relay
Expand Down
2 changes: 1 addition & 1 deletion modules/wallet/update.go
Expand Up @@ -560,7 +560,7 @@ func (w *Wallet) ReceiveUpdatedUnconfirmedTransactions(diff *modules.Transaction
// in commitTransactionSet. If it contains a subset it should be
// deleted and be replaced by the superset.
for tSetID, ids := range w.unconfirmedSets {
if isSuperset(unconfirmedTxnSet.IDs, ids) {
if isSuperset(unconfirmedTxnSet.IDs, ids) && len(unconfirmedTxnSet.IDs) != len(ids) {
// Remove the old id
delete(w.unconfirmedSets, tSetID)
if err := dbDeleteUnconfirmedSet(w.dbTx, tSetID); err != nil {
Expand Down
70 changes: 70 additions & 0 deletions modules/wallet/wallet_test.go
Expand Up @@ -591,3 +591,73 @@ func TestDistantWallets(t *testing.T) {
t.Fatal("wallet should not recognize coins sent to very high seed index")
}
}

// TestCommitTransactionSetInsufficientFees checks if a transaction still makes
// it into unconfirmedSets and unconfirmedProcessedTransactions even though the
// fees are not sufficient.
func TestCommitTransactionSetInsufficientFees(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
wt, err := createWalletTester(t.Name(), &ProductionDependencies{})
if err != nil {
t.Fatal(err)
}
defer wt.closeWt()

// Get an address from the wallet
uc, err := wt.wallet.NextAddress()
if err != nil {
t.Fatal(err)
}

// Send a bunch of transactions without fees. The transaction pool should
// expect an increasing number of fees once we hit the
// TransactionPoolSizeForFee limit but we will not add any to the
// transactions.
amount := types.SiacoinPrecision.Mul64(100)
poolSize := 0
numTxnsSent := 0
for poolSize < 2*transactionpool.TransactionPoolSizeForFee {
builder := wt.wallet.StartTransaction()
builder.AddSiacoinOutput(types.SiacoinOutput{
UnlockHash: uc.UnlockHash(),
Value: amount,
})
// Don't add any fees
err = builder.FundSiacoins(amount)
if err != nil {
t.Fatal(err)
}
txnSet, err := builder.Sign(true)
if err != nil {
t.Fatal(err)
}

// Committing the transaction should work
err = wt.wallet.managedCommitTransactionSet(txnSet)
if err != nil {
t.Fatal(err)
}

// Increase poolSize
for _, txn := range txnSet {
poolSize += txn.MarshalSiaSize()
}
numTxnsSent++
}
// Each sent transaction creates a set of 2 transactions. There hsould be
// the same number of unconfirmedProcessedTransactions
if len(wt.wallet.unconfirmedProcessedTransactions) != 2*numTxnsSent {
t.Errorf("There should be 2 txns for each sent set.")
}
// For each unfirmed processed transaction there should be a transaction id
// in the unconfirmedSets
unconfirmedSetsTxns := 0
for _, set := range wt.wallet.unconfirmedSets {
unconfirmedSetsTxns += len(set)
}
if len(wt.wallet.unconfirmedProcessedTransactions) != unconfirmedSetsTxns {
t.Errorf("There should be as many unconfirmed processed transactions as there are txns in the unconfirmed sets")
}
}

0 comments on commit 28a5e45

Please sign in to comment.