Skip to content

Commit

Permalink
get balance checks working again + adjust test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
jtieri committed Aug 8, 2023
1 parent 3ae3594 commit eb14aec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
14 changes: 4 additions & 10 deletions chain/penumbra/penumbra_client_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ func (p *PenumbraClientNode) GetBalance(ctx context.Context, denom string) (math
AccountFilter: &cryptov1alpha1.AddressIndex{
Account: 0,
},
AssetIdFilter: nil,
AssetIdFilter: &cryptov1alpha1.AssetId{
AltBaseDenom: denom,
},
}

// The BalanceByAddress method returns a stream response, containing
Expand All @@ -249,21 +251,14 @@ func (p *PenumbraClientNode) GetBalance(ctx context.Context, denom string) (math
if err != nil {
// A gRPC streaming response will return EOF when it's done.
if err == io.EOF {
fmt.Println("Found expected EOF error")
break
} else {
fmt.Println("Failed to get balance:", err)
return math.Int{}, err
}
}
fmt.Printf("Adding %v to balances array \n", balance)
balances = append(balances, balance)
}

fmt.Println("HERE DA BALANCES YO")
fmt.Printf("%v \n", balances)
fmt.Println()

//fmt.Println("In GetBalance, dumping all wallet contents...")
//for _, b := range balances {
// metadata, err := p.GetDenomMetadata(ctx, b.Balance.AssetId)
Expand All @@ -282,8 +277,7 @@ func (p *PenumbraClientNode) GetBalance(ctx context.Context, denom string) (math
// }
//}

// we should have found the specified denom balance by this point
return math.Int{}, fmt.Errorf("balance not found for specified denom %s", denom)
return translateHiAndLo(balances[0].Balance.Amount.Hi, balances[0].Balance.Amount.Lo), nil
}

// translateHiAndLo takes the high and low order bytes and decodes the two uint64 values into the single int128 value
Expand Down
31 changes: 18 additions & 13 deletions examples/penumbra/penumbra_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ func TestPenumbraChainStart(t *testing.T) {

chains, err := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
Name: "penumbra",
// Version: "040-themisto.1,v0.34.23",
Version: "v0.57.0,v0.34.24",
Name: "penumbra",
Version: "v0.58.0,v0.34.24",
ChainConfig: ibc.ChainConfig{
ChainID: "penumbra-1",
},
Expand Down Expand Up @@ -57,16 +56,19 @@ func TestPenumbraChainStart(t *testing.T) {
bob := chain.(*penumbra.PenumbraChain).PenumbraNodes[1]

aliceBal, err := chain.GetBalance(ctx, alice.PenumbraClientNodes["validator"].KeyName, chain.Config().Denom)
//require.NoError(t, err)
require.NoError(t, err)

bobBal, err := chain.GetBalance(ctx, bob.PenumbraClientNodes["validator"].KeyName, chain.Config().Denom)
//require.NoError(t, err)
require.NoError(t, err)

// TODO: genesis allocations should be configurable, right now we are using a hardcoded value in PenumbraChain.Start
expectedBal := math.NewInt(1_000_000_000_000)

t.Logf("Alice Balance: %s \n", aliceBal)
t.Logf("Bob Balance: %s \n", bobBal)

//bobAddr, err := bob.PenumbraAppNode.GetAddress(ctx, bob.PenumbraClientNodes["validator"].KeyName)
//require.NoError(t, err)
require.True(t, aliceBal.Equal(expectedBal))
require.True(t, bobBal.Equal(expectedBal))

transfer := ibc.WalletAmount{
Address: bob.PenumbraClientNodes["validator"].KeyName,
Expand All @@ -77,12 +79,15 @@ func TestPenumbraChainStart(t *testing.T) {
err = chain.SendFunds(ctx, alice.PenumbraClientNodes["validator"].KeyName, transfer)
require.NoError(t, err)

aliceBal, err = chain.GetBalance(ctx, alice.PenumbraClientNodes["validator"].KeyName, chain.Config().Denom)
//require.NoError(t, err)
aliceNewBal, err := chain.GetBalance(ctx, alice.PenumbraClientNodes["validator"].KeyName, chain.Config().Denom)
require.NoError(t, err)

bobNewBal, err := chain.GetBalance(ctx, bob.PenumbraClientNodes["validator"].KeyName, chain.Config().Denom)
require.NoError(t, err)

bobBal, err = chain.GetBalance(ctx, bob.PenumbraClientNodes["validator"].KeyName, chain.Config().Denom)
//require.NoError(t, err)
t.Logf("Alice Balance: %s \n", aliceNewBal)
t.Logf("Bob Balance: %s \n", bobNewBal)

t.Logf("Alice Balance: %s \n", aliceBal)
t.Logf("Bob Balance: %s \n", bobBal)
require.True(t, aliceNewBal.Equal(aliceBal.Sub(transfer.Amount)))
require.True(t, bobNewBal.Equal(bobBal.Add(transfer.Amount)))
}

0 comments on commit eb14aec

Please sign in to comment.