From a79b21b3730bf29f2c976394fbe03478cbd56c06 Mon Sep 17 00:00:00 2001 From: Artem Date: Thu, 22 Aug 2024 12:38:42 +0300 Subject: [PATCH] Fix: sudo and withdrawer is equal signer address --- pkg/indexer/decode/actions.go | 8 ++++-- pkg/indexer/decode/actions_test.go | 44 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/pkg/indexer/decode/actions.go b/pkg/indexer/decode/actions.go index 9a8a812..68abf55 100644 --- a/pkg/indexer/decode/actions.go +++ b/pkg/indexer/decode/actions.go @@ -383,7 +383,9 @@ func parseInitBridgeAccount(body *astria.Action_InitBridgeAccountAction, from st }) bridge.Sudo = addr } - } else { + } + + if bridge.Sudo == nil { bridge.Sudo = bridge.Address } @@ -400,7 +402,9 @@ func parseInitBridgeAccount(body *astria.Action_InitBridgeAccountAction, from st }) bridge.Withdrawer = addr } - } else { + } + + if bridge.Withdrawer == nil { bridge.Withdrawer = bridge.Address } diff --git a/pkg/indexer/decode/actions_test.go b/pkg/indexer/decode/actions_test.go index a1b7860..8892689 100644 --- a/pkg/indexer/decode/actions_test.go +++ b/pkg/indexer/decode/actions_test.go @@ -814,6 +814,50 @@ func TestDecodeActions(t *testing.T) { require.Equal(t, wantAction, action) }) + t.Run("init bridge account: the same address", func(t *testing.T) { + decodeContext := NewContext() + + rollupId := testsuite.RandomHash(10) + from := testsuite.RandomAddress() + message := &astria.Action_InitBridgeAccountAction{ + InitBridgeAccountAction: &astria.InitBridgeAccountAction{ + RollupId: &primitivev1.RollupId{Inner: rollupId}, + FeeAsset: feeAssetId, + Asset: assetId, + SudoAddress: &primitivev1.Address{Bech32M: from}, + WithdrawerAddress: &primitivev1.Address{Bech32M: from}, + }, + } + + wantAction := storage.Action{ + Height: 1000, + Type: types.ActionTypeInitBridgeAccount, + Data: map[string]any{ + "rollup_id": rollupId, + "asset": assetId, + "fee_asset": feeAssetId, + "sudo": from, + "withdrawer": from, + }, + RollupAction: &storage.RollupAction{ + Height: 1000, + Rollup: &storage.Rollup{ + AstriaId: message.InitBridgeAccountAction.GetRollupId().GetInner(), + FirstHeight: 1000, + ActionsCount: 1, + }, + }, + } + wantAction.RollupAction.Action = &wantAction + + action := storage.Action{ + Height: 1000, + } + err := parseInitBridgeAccount(message, from, 1000, &decodeContext, &action) + require.NoError(t, err) + require.Equal(t, wantAction, action) + }) + t.Run("ibc relayer change: addition", func(t *testing.T) { decodeContext := NewContext()