-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package handle | ||
|
||
import ( | ||
"github.com/celenium-io/celestia-indexer/internal/storage" | ||
storageTypes "github.com/celenium-io/celestia-indexer/internal/storage/types" | ||
"github.com/celenium-io/celestia-indexer/pkg/types" | ||
coreConnection "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types" | ||
) | ||
|
||
// MsgConnectionOpenInit defines the msg sent by an account on Chain A to initialize a connection with Chain B. | ||
func MsgConnectionOpenInit(level types.Level, m *coreConnection.MsgConnectionOpenInit) (storageTypes.MsgType, []storage.AddressWithType, error) { | ||
msgType := storageTypes.MsgConnectionOpenInit | ||
addresses, err := createAddresses(addressesData{ | ||
{t: storageTypes.MsgAddressTypeSigner, address: m.Signer}, | ||
}, level) | ||
return msgType, addresses, err | ||
} | ||
|
||
// MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a connection on Chain B. | ||
func MsgConnectionOpenTry(level types.Level, m *coreConnection.MsgConnectionOpenTry) (storageTypes.MsgType, []storage.AddressWithType, error) { | ||
msgType := storageTypes.MsgConnectionOpenTry | ||
addresses, err := createAddresses(addressesData{ | ||
{t: storageTypes.MsgAddressTypeSigner, address: m.Signer}, | ||
}, level) | ||
return msgType, addresses, err | ||
} | ||
|
||
// MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to | ||
// acknowledge the change of connection state to TRYOPEN on Chain B. | ||
func MsgConnectionOpenAck(level types.Level, m *coreConnection.MsgConnectionOpenAck) (storageTypes.MsgType, []storage.AddressWithType, error) { | ||
msgType := storageTypes.MsgConnectionOpenAck | ||
addresses, err := createAddresses(addressesData{ | ||
{t: storageTypes.MsgAddressTypeSigner, address: m.Signer}, | ||
}, level) | ||
return msgType, addresses, err | ||
} | ||
|
||
// MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to | ||
// acknowledge the change of connection state to OPEN on Chain A. | ||
func MsgConnectionOpenConfirm(level types.Level, m *coreConnection.MsgConnectionOpenConfirm) (storageTypes.MsgType, []storage.AddressWithType, error) { | ||
msgType := storageTypes.MsgConnectionOpenConfirm | ||
addresses, err := createAddresses(addressesData{ | ||
{t: storageTypes.MsgAddressTypeSigner, address: m.Signer}, | ||
}, level) | ||
return msgType, addresses, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
package handle | ||
|
||
import ( | ||
"github.com/celenium-io/celestia-indexer/internal/storage" | ||
storageTypes "github.com/celenium-io/celestia-indexer/internal/storage/types" | ||
testsuite "github.com/celenium-io/celestia-indexer/internal/test_suite" | ||
"github.com/celenium-io/celestia-indexer/pkg/indexer/decode" | ||
coreConnection "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types" | ||
"github.com/fatih/structs" | ||
"github.com/shopspring/decimal" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestDecodeMsg_SuccessOnMsgConnectionOpenInit(t *testing.T) { | ||
msg := &coreConnection.MsgConnectionOpenInit{ | ||
Signer: "celestia1j33593mn9urzydakw06jdun8f37shlucmhr8p6", | ||
} | ||
blob, now := testsuite.EmptyBlock() | ||
position := 0 | ||
|
||
dm, err := decode.Message(msg, blob.Height, blob.Block.Time, position, storageTypes.StatusSuccess) | ||
|
||
addressesExpected := []storage.AddressWithType{ | ||
{ | ||
Type: storageTypes.MsgAddressTypeSigner, | ||
Address: storage.Address{ | ||
Id: 0, | ||
Height: blob.Height, | ||
LastHeight: blob.Height, | ||
Address: "celestia1j33593mn9urzydakw06jdun8f37shlucmhr8p6", | ||
Hash: []byte{0x94, 0x63, 0x42, 0xc7, 0x73, 0x2f, 0x6, 0x22, 0x37, 0xb6, 0x73, 0xf5, 0x26, 0xf2, 0x67, 0x4c, 0x7d, 0xb, 0xff, 0x98}, | ||
Balance: storage.Balance{ | ||
Id: 0, | ||
Total: decimal.Zero, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
msgExpected := storage.Message{ | ||
Id: 0, | ||
Height: blob.Height, | ||
Time: now, | ||
Position: 0, | ||
Type: storageTypes.MsgConnectionOpenInit, | ||
TxId: 0, | ||
Data: structs.Map(msg), | ||
Namespace: nil, | ||
Addresses: addressesExpected, | ||
} | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, int64(0), dm.BlobsSize) | ||
assert.Equal(t, msgExpected, dm.Msg) | ||
assert.Equal(t, addressesExpected, dm.Addresses) | ||
} | ||
|
||
func TestDecodeMsg_SuccessOnMsgConnectionOpenTry(t *testing.T) { | ||
msg := &coreConnection.MsgConnectionOpenTry{ | ||
Signer: "celestia1j33593mn9urzydakw06jdun8f37shlucmhr8p6", | ||
} | ||
blob, now := testsuite.EmptyBlock() | ||
position := 0 | ||
|
||
dm, err := decode.Message(msg, blob.Height, blob.Block.Time, position, storageTypes.StatusSuccess) | ||
|
||
addressesExpected := []storage.AddressWithType{ | ||
{ | ||
Type: storageTypes.MsgAddressTypeSigner, | ||
Address: storage.Address{ | ||
Id: 0, | ||
Height: blob.Height, | ||
LastHeight: blob.Height, | ||
Address: "celestia1j33593mn9urzydakw06jdun8f37shlucmhr8p6", | ||
Hash: []byte{0x94, 0x63, 0x42, 0xc7, 0x73, 0x2f, 0x6, 0x22, 0x37, 0xb6, 0x73, 0xf5, 0x26, 0xf2, 0x67, 0x4c, 0x7d, 0xb, 0xff, 0x98}, | ||
Balance: storage.Balance{ | ||
Id: 0, | ||
Total: decimal.Zero, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
msgExpected := storage.Message{ | ||
Id: 0, | ||
Height: blob.Height, | ||
Time: now, | ||
Position: 0, | ||
Type: storageTypes.MsgConnectionOpenTry, | ||
TxId: 0, | ||
Data: structs.Map(msg), | ||
Namespace: nil, | ||
Addresses: addressesExpected, | ||
} | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, int64(0), dm.BlobsSize) | ||
assert.Equal(t, msgExpected, dm.Msg) | ||
assert.Equal(t, addressesExpected, dm.Addresses) | ||
} | ||
|
||
func TestDecodeMsg_SuccessOnMsgConnectionOpenAck(t *testing.T) { | ||
msg := &coreConnection.MsgConnectionOpenAck{ | ||
Signer: "celestia1j33593mn9urzydakw06jdun8f37shlucmhr8p6", | ||
} | ||
blob, now := testsuite.EmptyBlock() | ||
position := 0 | ||
|
||
dm, err := decode.Message(msg, blob.Height, blob.Block.Time, position, storageTypes.StatusSuccess) | ||
|
||
addressesExpected := []storage.AddressWithType{ | ||
{ | ||
Type: storageTypes.MsgAddressTypeSigner, | ||
Address: storage.Address{ | ||
Id: 0, | ||
Height: blob.Height, | ||
LastHeight: blob.Height, | ||
Address: "celestia1j33593mn9urzydakw06jdun8f37shlucmhr8p6", | ||
Hash: []byte{0x94, 0x63, 0x42, 0xc7, 0x73, 0x2f, 0x6, 0x22, 0x37, 0xb6, 0x73, 0xf5, 0x26, 0xf2, 0x67, 0x4c, 0x7d, 0xb, 0xff, 0x98}, | ||
Balance: storage.Balance{ | ||
Id: 0, | ||
Total: decimal.Zero, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
msgExpected := storage.Message{ | ||
Id: 0, | ||
Height: blob.Height, | ||
Time: now, | ||
Position: 0, | ||
Type: storageTypes.MsgConnectionOpenAck, | ||
TxId: 0, | ||
Data: structs.Map(msg), | ||
Namespace: nil, | ||
Addresses: addressesExpected, | ||
} | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, int64(0), dm.BlobsSize) | ||
assert.Equal(t, msgExpected, dm.Msg) | ||
assert.Equal(t, addressesExpected, dm.Addresses) | ||
} | ||
|
||
func TestDecodeMsg_SuccessOnMsgConnectionOpenConfirm(t *testing.T) { | ||
msg := &coreConnection.MsgConnectionOpenConfirm{ | ||
Signer: "celestia1j33593mn9urzydakw06jdun8f37shlucmhr8p6", | ||
} | ||
blob, now := testsuite.EmptyBlock() | ||
position := 0 | ||
|
||
dm, err := decode.Message(msg, blob.Height, blob.Block.Time, position, storageTypes.StatusSuccess) | ||
|
||
addressesExpected := []storage.AddressWithType{ | ||
{ | ||
Type: storageTypes.MsgAddressTypeSigner, | ||
Address: storage.Address{ | ||
Id: 0, | ||
Height: blob.Height, | ||
LastHeight: blob.Height, | ||
Address: "celestia1j33593mn9urzydakw06jdun8f37shlucmhr8p6", | ||
Hash: []byte{0x94, 0x63, 0x42, 0xc7, 0x73, 0x2f, 0x6, 0x22, 0x37, 0xb6, 0x73, 0xf5, 0x26, 0xf2, 0x67, 0x4c, 0x7d, 0xb, 0xff, 0x98}, | ||
Balance: storage.Balance{ | ||
Id: 0, | ||
Total: decimal.Zero, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
msgExpected := storage.Message{ | ||
Id: 0, | ||
Height: blob.Height, | ||
Time: now, | ||
Position: 0, | ||
Type: storageTypes.MsgConnectionOpenConfirm, | ||
TxId: 0, | ||
Data: structs.Map(msg), | ||
Namespace: nil, | ||
Addresses: addressesExpected, | ||
} | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, int64(0), dm.BlobsSize) | ||
assert.Equal(t, msgExpected, dm.Msg) | ||
assert.Equal(t, addressesExpected, dm.Addresses) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters