Skip to content

Commit

Permalink
test(frame): tx-payment (#236)
Browse files Browse the repository at this point in the history
* test(frame): tx-payment

* refactor

* more test cases
  • Loading branch information
radkomih authored Oct 12, 2023
1 parent 80d83f0 commit 9b679b7
Show file tree
Hide file tree
Showing 7 changed files with 731 additions and 2 deletions.
Binary file modified build/runtime.wasm
Binary file not shown.
40 changes: 40 additions & 0 deletions frame/transaction_payment/event_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package transaction_payment

import (
"bytes"
"testing"

sc "github.com/LimeChain/goscale"
"github.com/LimeChain/gosemble/primitives/types"
"github.com/stretchr/testify/assert"
)

func Test_DecodeEvent(t *testing.T) {
buffer := bytes.NewBuffer([]byte{})
expectedEvent := NewEventTransactionFeePaid(moduleId, who.FixedSequence, sc.NewU128(7), sc.NewU128(1))
expectedEvent.Encode(buffer)

result := DecodeEvent(moduleId, buffer)

assert.Equal(t, expectedEvent, result)
}

func Test_DecodeEvent_ModuleIndexError(t *testing.T) {
buffer := bytes.NewBuffer([]byte{})
expectedEvent := NewEventTransactionFeePaid(moduleId, who.FixedSequence, sc.NewU128(7), sc.NewU128(1))
expectedEvent.Encode(buffer)

assert.PanicsWithValue(t, "invalid transaction_payment.Event module", func() {
DecodeEvent(sc.U8(123), buffer)
})
}

func Test_DecodeEvent_TypeError(t *testing.T) {
buffer := bytes.NewBuffer([]byte{})
expectedEvent := types.NewEvent(moduleId, 99, who.FixedSequence, sc.NewU128(7), sc.NewU128(1))
expectedEvent.Encode(buffer)

assert.PanicsWithValue(t, "invalid transaction_payment.Event type", func() {
DecodeEvent(moduleId, buffer)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,20 @@ func (ctp ChargeTransactionPayment) PostDispatch(pre sc.Option[primitives.Pre],
imbalance := preValue[2].(sc.Option[primitives.Balance])

actualFee := ctp.txPaymentModule.ComputeActualFee(sc.U32(length.ToBigInt().Uint64()), *info, *postInfo, tip)

err := ctp.onChargeTransaction.CorrectAndDepositFee(who, actualFee, tip, imbalance)
if err != nil {
return err
}

ctp.systemModule.DepositEvent(transaction_payment.NewEventTransactionFeePaid(ctp.txPaymentModule.GetIndex(), who.FixedSequence, actualFee, tip))
ctp.systemModule.DepositEvent(
transaction_payment.NewEventTransactionFeePaid(
ctp.txPaymentModule.GetIndex(),
who.FixedSequence,
actualFee,
tip,
),
)
}
return nil
}
Expand Down
Loading

0 comments on commit 9b679b7

Please sign in to comment.