forked from TrueCloudLab/frostfs-node
[#280] ir: Add frostfs processor unit tests
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
5010b35466
commit
31b4da225a
16 changed files with 491 additions and 104 deletions
|
@ -11,31 +11,31 @@ import (
|
|||
)
|
||||
|
||||
type Bind struct {
|
||||
bindCommon
|
||||
BindCommon
|
||||
}
|
||||
|
||||
type bindCommon struct {
|
||||
user []byte
|
||||
keys [][]byte
|
||||
type BindCommon struct {
|
||||
UserValue []byte
|
||||
KeysValue [][]byte
|
||||
|
||||
// txHash is used in notary environmental
|
||||
// TxHashValue is used in notary environmental
|
||||
// for calculating unique but same for
|
||||
// all notification receivers values.
|
||||
txHash util.Uint256
|
||||
TxHashValue util.Uint256
|
||||
}
|
||||
|
||||
// TxHash returns hash of the TX with new epoch
|
||||
// notification.
|
||||
func (b bindCommon) TxHash() util.Uint256 {
|
||||
return b.txHash
|
||||
func (b BindCommon) TxHash() util.Uint256 {
|
||||
return b.TxHashValue
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (bindCommon) MorphEvent() {}
|
||||
func (BindCommon) MorphEvent() {}
|
||||
|
||||
func (b bindCommon) Keys() [][]byte { return b.keys }
|
||||
func (b BindCommon) Keys() [][]byte { return b.KeysValue }
|
||||
|
||||
func (b bindCommon) User() []byte { return b.user }
|
||||
func (b BindCommon) User() []byte { return b.UserValue }
|
||||
|
||||
func ParseBind(e *state.ContainedNotificationEvent) (event.Event, error) {
|
||||
var (
|
||||
|
@ -48,17 +48,17 @@ func ParseBind(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not parse stack items from notify event: %w", err)
|
||||
}
|
||||
|
||||
err = parseBind(&ev.bindCommon, params)
|
||||
err = parseBind(&ev.BindCommon, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ev.txHash = e.Container
|
||||
ev.TxHashValue = e.Container
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
||||
func parseBind(dst *bindCommon, params []stackitem.Item) error {
|
||||
func parseBind(dst *BindCommon, params []stackitem.Item) error {
|
||||
if ln := len(params); ln != 2 {
|
||||
return event.WrongNumberOfParameters(2, ln)
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func parseBind(dst *bindCommon, params []stackitem.Item) error {
|
|||
var err error
|
||||
|
||||
// parse user
|
||||
dst.user, err = client.BytesFromStackItem(params[0])
|
||||
dst.UserValue, err = client.BytesFromStackItem(params[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get bind user: %w", err)
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func parseBind(dst *bindCommon, params []stackitem.Item) error {
|
|||
return fmt.Errorf("could not get bind keys: %w", err)
|
||||
}
|
||||
|
||||
dst.keys = make([][]byte, 0, len(bindKeys))
|
||||
dst.KeysValue = make([][]byte, 0, len(bindKeys))
|
||||
|
||||
for i := range bindKeys {
|
||||
rawKey, err := client.BytesFromStackItem(bindKeys[i])
|
||||
|
@ -85,7 +85,7 @@ func parseBind(dst *bindCommon, params []stackitem.Item) error {
|
|||
return fmt.Errorf("could not get bind public key: %w", err)
|
||||
}
|
||||
|
||||
dst.keys = append(dst.keys, rawKey)
|
||||
dst.KeysValue = append(dst.KeysValue, rawKey)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -11,26 +11,26 @@ import (
|
|||
|
||||
// Cheque structure of frostfs.Cheque notification from mainnet chain.
|
||||
type Cheque struct {
|
||||
id []byte
|
||||
amount int64 // Fixed8
|
||||
user util.Uint160
|
||||
lock util.Uint160
|
||||
IDValue []byte
|
||||
AmountValue int64 // Fixed8
|
||||
UserValue util.Uint160
|
||||
LockValue util.Uint160
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (Cheque) MorphEvent() {}
|
||||
|
||||
// ID is a withdraw transaction hash.
|
||||
func (c Cheque) ID() []byte { return c.id }
|
||||
func (c Cheque) ID() []byte { return c.IDValue }
|
||||
|
||||
// User returns withdraw receiver script hash from main net.
|
||||
func (c Cheque) User() util.Uint160 { return c.user }
|
||||
func (c Cheque) User() util.Uint160 { return c.UserValue }
|
||||
|
||||
// Amount of the sent assets.
|
||||
func (c Cheque) Amount() int64 { return c.amount }
|
||||
func (c Cheque) Amount() int64 { return c.AmountValue }
|
||||
|
||||
// LockAccount return script hash for balance contract wallet.
|
||||
func (c Cheque) LockAccount() util.Uint160 { return c.lock }
|
||||
func (c Cheque) LockAccount() util.Uint160 { return c.LockValue }
|
||||
|
||||
// ParseCheque from notification into cheque structure.
|
||||
func ParseCheque(e *state.ContainedNotificationEvent) (event.Event, error) {
|
||||
|
@ -49,7 +49,7 @@ func ParseCheque(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
}
|
||||
|
||||
// parse id
|
||||
ev.id, err = client.BytesFromStackItem(params[0])
|
||||
ev.IDValue, err = client.BytesFromStackItem(params[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get cheque id: %w", err)
|
||||
}
|
||||
|
@ -60,13 +60,13 @@ func ParseCheque(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not get cheque user: %w", err)
|
||||
}
|
||||
|
||||
ev.user, err = util.Uint160DecodeBytesBE(user)
|
||||
ev.UserValue, err = util.Uint160DecodeBytesBE(user)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not convert cheque user to uint160: %w", err)
|
||||
}
|
||||
|
||||
// parse amount
|
||||
ev.amount, err = client.IntFromStackItem(params[2])
|
||||
ev.AmountValue, err = client.IntFromStackItem(params[2])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get cheque amount: %w", err)
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func ParseCheque(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not get cheque lock account: %w", err)
|
||||
}
|
||||
|
||||
ev.lock, err = util.Uint160DecodeBytesBE(lock)
|
||||
ev.LockValue, err = util.Uint160DecodeBytesBE(lock)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not convert cheque lock account to uint160: %w", err)
|
||||
}
|
||||
|
|
|
@ -77,10 +77,10 @@ func TestParseCheque(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, Cheque{
|
||||
id: id,
|
||||
amount: amount,
|
||||
user: user,
|
||||
lock: lock,
|
||||
IDValue: id,
|
||||
AmountValue: amount,
|
||||
UserValue: user,
|
||||
LockValue: lock,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -10,30 +10,30 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
key []byte
|
||||
value []byte
|
||||
id []byte
|
||||
KeyValue []byte
|
||||
ValueValue []byte
|
||||
IDValue []byte
|
||||
|
||||
// txHash is used in notary environmental
|
||||
// TxHashValue is used in notary environmental
|
||||
// for calculating unique but same for
|
||||
// all notification receivers values.
|
||||
txHash util.Uint256
|
||||
TxHashValue util.Uint256
|
||||
}
|
||||
|
||||
// TxHash returns hash of the TX with new epoch
|
||||
// notification.
|
||||
func (u Config) TxHash() util.Uint256 {
|
||||
return u.txHash
|
||||
return u.TxHashValue
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (Config) MorphEvent() {}
|
||||
|
||||
func (u Config) ID() []byte { return u.id }
|
||||
func (u Config) ID() []byte { return u.IDValue }
|
||||
|
||||
func (u Config) Key() []byte { return u.key }
|
||||
func (u Config) Key() []byte { return u.KeyValue }
|
||||
|
||||
func (u Config) Value() []byte { return u.value }
|
||||
func (u Config) Value() []byte { return u.ValueValue }
|
||||
|
||||
func ParseConfig(e *state.ContainedNotificationEvent) (event.Event, error) {
|
||||
var (
|
||||
|
@ -51,24 +51,24 @@ func ParseConfig(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
}
|
||||
|
||||
// parse id
|
||||
ev.id, err = client.BytesFromStackItem(params[0])
|
||||
ev.IDValue, err = client.BytesFromStackItem(params[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get config update id: %w", err)
|
||||
}
|
||||
|
||||
// parse key
|
||||
ev.key, err = client.BytesFromStackItem(params[1])
|
||||
ev.KeyValue, err = client.BytesFromStackItem(params[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get config key: %w", err)
|
||||
}
|
||||
|
||||
// parse value
|
||||
ev.value, err = client.BytesFromStackItem(params[2])
|
||||
ev.ValueValue, err = client.BytesFromStackItem(params[2])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get config value: %w", err)
|
||||
}
|
||||
|
||||
ev.txHash = e.Container
|
||||
ev.TxHashValue = e.Container
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
|
|
@ -60,9 +60,9 @@ func TestParseConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, Config{
|
||||
id: id,
|
||||
key: key,
|
||||
value: value,
|
||||
IDValue: id,
|
||||
KeyValue: key,
|
||||
ValueValue: value,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,26 +11,26 @@ import (
|
|||
|
||||
// Deposit structure of frostfs.Deposit notification from mainnet chain.
|
||||
type Deposit struct {
|
||||
id []byte
|
||||
amount int64 // Fixed8
|
||||
from util.Uint160
|
||||
to util.Uint160
|
||||
IDValue []byte
|
||||
AmountValue int64 // Fixed8
|
||||
FromValue util.Uint160
|
||||
ToValue util.Uint160
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (Deposit) MorphEvent() {}
|
||||
|
||||
// ID is a deposit transaction hash.
|
||||
func (d Deposit) ID() []byte { return d.id }
|
||||
func (d Deposit) ID() []byte { return d.IDValue }
|
||||
|
||||
// From is a script hash of asset sender in main net.
|
||||
func (d Deposit) From() util.Uint160 { return d.from }
|
||||
func (d Deposit) From() util.Uint160 { return d.FromValue }
|
||||
|
||||
// To is a script hash of asset receiver in balance contract.
|
||||
func (d Deposit) To() util.Uint160 { return d.to }
|
||||
func (d Deposit) To() util.Uint160 { return d.ToValue }
|
||||
|
||||
// Amount of transferred assets.
|
||||
func (d Deposit) Amount() int64 { return d.amount }
|
||||
func (d Deposit) Amount() int64 { return d.AmountValue }
|
||||
|
||||
// ParseDeposit notification into deposit structure.
|
||||
func ParseDeposit(e *state.ContainedNotificationEvent) (event.Event, error) {
|
||||
|
@ -51,13 +51,13 @@ func ParseDeposit(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not get deposit sender: %w", err)
|
||||
}
|
||||
|
||||
ev.from, err = util.Uint160DecodeBytesBE(from)
|
||||
ev.FromValue, err = util.Uint160DecodeBytesBE(from)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not convert deposit sender to uint160: %w", err)
|
||||
}
|
||||
|
||||
// parse amount
|
||||
ev.amount, err = client.IntFromStackItem(params[1])
|
||||
ev.AmountValue, err = client.IntFromStackItem(params[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get deposit amount: %w", err)
|
||||
}
|
||||
|
@ -68,13 +68,13 @@ func ParseDeposit(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not get deposit receiver: %w", err)
|
||||
}
|
||||
|
||||
ev.to, err = util.Uint160DecodeBytesBE(to)
|
||||
ev.ToValue, err = util.Uint160DecodeBytesBE(to)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not convert deposit receiver to uint160: %w", err)
|
||||
}
|
||||
|
||||
// parse id
|
||||
ev.id, err = client.BytesFromStackItem(params[3])
|
||||
ev.IDValue, err = client.BytesFromStackItem(params[3])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get deposit id: %w", err)
|
||||
}
|
||||
|
|
|
@ -77,10 +77,10 @@ func TestParseDeposit(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, Deposit{
|
||||
id: id,
|
||||
amount: amount,
|
||||
from: from,
|
||||
to: to,
|
||||
IDValue: id,
|
||||
AmountValue: amount,
|
||||
FromValue: from,
|
||||
ToValue: to,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
type Unbind struct {
|
||||
bindCommon
|
||||
BindCommon
|
||||
}
|
||||
|
||||
func ParseUnbind(e *state.ContainedNotificationEvent) (event.Event, error) {
|
||||
|
@ -22,12 +22,12 @@ func ParseUnbind(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not parse stack items from notify event: %w", err)
|
||||
}
|
||||
|
||||
err = parseBind(&ev.bindCommon, params)
|
||||
err = parseBind(&ev.BindCommon, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ev.txHash = e.Container
|
||||
ev.TxHashValue = e.Container
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
|
|
@ -11,22 +11,22 @@ import (
|
|||
|
||||
// Withdraw structure of frostfs.Withdraw notification from mainnet chain.
|
||||
type Withdraw struct {
|
||||
id []byte
|
||||
amount int64 // Fixed8
|
||||
user util.Uint160
|
||||
IDValue []byte
|
||||
AmountValue int64 // Fixed8
|
||||
UserValue util.Uint160
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (Withdraw) MorphEvent() {}
|
||||
|
||||
// ID is a withdraw transaction hash.
|
||||
func (w Withdraw) ID() []byte { return w.id }
|
||||
func (w Withdraw) ID() []byte { return w.IDValue }
|
||||
|
||||
// User returns withdraw receiver script hash from main net.
|
||||
func (w Withdraw) User() util.Uint160 { return w.user }
|
||||
func (w Withdraw) User() util.Uint160 { return w.UserValue }
|
||||
|
||||
// Amount of the withdraw assets.
|
||||
func (w Withdraw) Amount() int64 { return w.amount }
|
||||
func (w Withdraw) Amount() int64 { return w.AmountValue }
|
||||
|
||||
// ParseWithdraw notification into withdraw structure.
|
||||
func ParseWithdraw(e *state.ContainedNotificationEvent) (event.Event, error) {
|
||||
|
@ -47,19 +47,19 @@ func ParseWithdraw(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not get withdraw user: %w", err)
|
||||
}
|
||||
|
||||
ev.user, err = util.Uint160DecodeBytesBE(user)
|
||||
ev.UserValue, err = util.Uint160DecodeBytesBE(user)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not convert withdraw user to uint160: %w", err)
|
||||
}
|
||||
|
||||
// parse amount
|
||||
ev.amount, err = client.IntFromStackItem(params[1])
|
||||
ev.AmountValue, err = client.IntFromStackItem(params[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get withdraw amount: %w", err)
|
||||
}
|
||||
|
||||
// parse id
|
||||
ev.id, err = client.BytesFromStackItem(params[2])
|
||||
ev.IDValue, err = client.BytesFromStackItem(params[2])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get withdraw id: %w", err)
|
||||
}
|
||||
|
|
|
@ -64,9 +64,9 @@ func TestParseWithdraw(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, Withdraw{
|
||||
id: id,
|
||||
amount: amount,
|
||||
user: user,
|
||||
IDValue: id,
|
||||
AmountValue: amount,
|
||||
UserValue: user,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue