Skip to content

Commit

Permalink
rm old debugging files
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Oct 10, 2023
1 parent ce06675 commit f086b77
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 238 deletions.
236 changes: 117 additions & 119 deletions middleware/packet-forward-middleware/e2e/packet_forward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,155 +178,153 @@ func TestPacketForwardMiddleware(t *testing.T) {
zeroBal := math.ZeroInt()
transferAmount := math.NewInt(100_000)

/*
t.Run("multi-hop a->b->c->d", func(t *testing.T) {
// Send packet from Chain A->Chain B->Chain C->Chain D
transfer := ibc.WalletAmount{
Address: userB.FormattedAddress(),
Denom: chainA.Config().Denom,
Amount: transferAmount,
}
t.Run("multi-hop a->b->c->d", func(t *testing.T) {
// Send packet from Chain A->Chain B->Chain C->Chain D
transfer := ibc.WalletAmount{
Address: userB.FormattedAddress(),
Denom: chainA.Config().Denom,
Amount: transferAmount,
}

secondHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userD.FormattedAddress(),
Channel: cdChan.ChannelID,
Port: cdChan.PortID,
},
}
nextBz, err := json.Marshal(secondHopMetadata)
require.NoError(t, err)
next := string(nextBz)
firstHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userC.FormattedAddress(),
Channel: bcChan.ChannelID,
Port: bcChan.PortID,
Next: &next,
},
}
secondHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userD.FormattedAddress(),
Channel: cdChan.ChannelID,
Port: cdChan.PortID,
},
}
nextBz, err := json.Marshal(secondHopMetadata)
require.NoError(t, err)
next := string(nextBz)

memo, err := json.Marshal(firstHopMetadata)
require.NoError(t, err)
firstHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userC.FormattedAddress(),
Channel: bcChan.ChannelID,
Port: bcChan.PortID,
Next: &next,
},
}

chainAHeight, err := chainA.Height(ctx)
require.NoError(t, err)
memo, err := json.Marshal(firstHopMetadata)
require.NoError(t, err)

transferTx, err := chainA.SendIBCTransfer(ctx, abChan.ChannelID, userA.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)
_, err = testutil.PollForAck(ctx, chainA, chainAHeight, chainAHeight+30, transferTx.Packet)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, waitBlocks, chainA)
require.NoError(t, err)
chainAHeight, err := chainA.Height(ctx)
require.NoError(t, err)

chainABalance, err := chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)
transferTx, err := chainA.SendIBCTransfer(ctx, abChan.ChannelID, userA.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)
_, err = testutil.PollForAck(ctx, chainA, chainAHeight, chainAHeight+30, transferTx.Packet)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, waitBlocks, chainA)
require.NoError(t, err)

chainBBalance, err := chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)
chainABalance, err := chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)

chainCBalance, err := chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)
chainBBalance, err := chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)

chainDBalance, err := chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom)
require.NoError(t, err)
chainCBalance, err := chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)

require.True(t, chainABalance.Equal(initBal.Sub(transferAmount)))
require.True(t, chainBBalance.Equal(zeroBal))
require.True(t, chainCBalance.Equal(zeroBal))
require.True(t, chainDBalance.Equal(transferAmount))
chainDBalance, err := chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom)
require.NoError(t, err)

firstHopEscrowBalance, err := chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)
require.True(t, chainABalance.Equal(initBal.Sub(transferAmount)))
require.True(t, chainBBalance.Equal(zeroBal))
require.True(t, chainCBalance.Equal(zeroBal))
require.True(t, chainDBalance.Equal(transferAmount))

secondHopEscrowBalance, err := chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)
firstHopEscrowBalance, err := chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)

thirdHopEscrowBalance, err := chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom)
require.NoError(t, err)
secondHopEscrowBalance, err := chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)

require.Equal(t, transferAmount, firstHopEscrowBalance)
require.Equal(t, transferAmount, secondHopEscrowBalance)
require.Equal(t, transferAmount, thirdHopEscrowBalance)
})
thirdHopEscrowBalance, err := chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom)
require.NoError(t, err)

t.Run("multi-hop denom unwind d->c->b->a", func(t *testing.T) {
// Send packet back from Chain D->Chain C->Chain B->Chain A
transfer := ibc.WalletAmount{
Address: userC.FormattedAddress(),
Denom: thirdHopIBCDenom,
Amount: transferAmount,
}
require.Equal(t, transferAmount, firstHopEscrowBalance)
require.Equal(t, transferAmount, secondHopEscrowBalance)
require.Equal(t, transferAmount, thirdHopEscrowBalance)
})

secondHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userA.FormattedAddress(),
Channel: baChan.ChannelID,
Port: baChan.PortID,
},
}
t.Run("multi-hop denom unwind d->c->b->a", func(t *testing.T) {
// Send packet back from Chain D->Chain C->Chain B->Chain A
transfer := ibc.WalletAmount{
Address: userC.FormattedAddress(),
Denom: thirdHopIBCDenom,
Amount: transferAmount,
}

nextBz, err := json.Marshal(secondHopMetadata)
require.NoError(t, err)
secondHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userA.FormattedAddress(),
Channel: baChan.ChannelID,
Port: baChan.PortID,
},
}

next := string(nextBz)
nextBz, err := json.Marshal(secondHopMetadata)
require.NoError(t, err)

firstHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userB.FormattedAddress(),
Channel: cbChan.ChannelID,
Port: cbChan.PortID,
Next: &next,
},
}
next := string(nextBz)

memo, err := json.Marshal(firstHopMetadata)
require.NoError(t, err)
firstHopMetadata := &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userB.FormattedAddress(),
Channel: cbChan.ChannelID,
Port: cbChan.PortID,
Next: &next,
},
}

chainDHeight, err := chainD.Height(ctx)
require.NoError(t, err)
memo, err := json.Marshal(firstHopMetadata)
require.NoError(t, err)

transferTx, err := chainD.SendIBCTransfer(ctx, dcChan.ChannelID, userD.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)
_, err = testutil.PollForAck(ctx, chainD, chainDHeight, chainDHeight+30, transferTx.Packet)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, waitBlocks, chainA)
require.NoError(t, err)
chainDHeight, err := chainD.Height(ctx)
require.NoError(t, err)

// assert balances for user controlled wallets
chainDBalance, err := chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom)
require.NoError(t, err)
transferTx, err := chainD.SendIBCTransfer(ctx, dcChan.ChannelID, userD.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)
_, err = testutil.PollForAck(ctx, chainD, chainDHeight, chainDHeight+30, transferTx.Packet)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, waitBlocks, chainA)
require.NoError(t, err)

chainCBalance, err := chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)
// assert balances for user controlled wallets
chainDBalance, err := chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom)
require.NoError(t, err)

chainBBalance, err := chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)
chainCBalance, err := chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)

chainABalance, err := chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)
chainBBalance, err := chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)

require.True(t, chainDBalance.Equal(zeroBal))
require.True(t, chainCBalance.Equal(zeroBal))
require.True(t, chainBBalance.Equal(zeroBal))
require.True(t, chainABalance.Equal(initBal))
chainABalance, err := chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)

require.True(t, chainDBalance.Equal(zeroBal))
require.True(t, chainCBalance.Equal(zeroBal))
require.True(t, chainBBalance.Equal(zeroBal))
require.True(t, chainABalance.Equal(initBal))

// assert balances for IBC escrow accounts
firstHopEscrowBalance, err := chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)
// assert balances for IBC escrow accounts
firstHopEscrowBalance, err := chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)

secondHopEscrowBalance, err := chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)
secondHopEscrowBalance, err := chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)

thirdHopEscrowBalance, err := chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom)
require.NoError(t, err)
thirdHopEscrowBalance, err := chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom)
require.NoError(t, err)

require.True(t, firstHopEscrowBalance.Equal(zeroBal))
require.True(t, secondHopEscrowBalance.Equal(zeroBal))
require.True(t, thirdHopEscrowBalance.Equal(zeroBal))
})
*/
require.True(t, firstHopEscrowBalance.Equal(zeroBal))
require.True(t, secondHopEscrowBalance.Equal(zeroBal))
require.True(t, thirdHopEscrowBalance.Equal(zeroBal))
})

t.Run("forward ack error refund", func(t *testing.T) {
// Send a malformed packet with invalid receiver address from Chain A->Chain B->Chain C
Expand Down
119 changes: 0 additions & 119 deletions middleware/packet-forward-middleware/test_node.sh

This file was deleted.

Binary file not shown.
Binary file not shown.

0 comments on commit f086b77

Please sign in to comment.