Skip to content

Commit

Permalink
Fix transaction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lrettig committed Nov 5, 2024
1 parent 6e7942f commit bb5dc73
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions api/grpcserver/v2alpha1/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"math/rand"
"os"
"testing"
"time"

Expand All @@ -27,10 +28,16 @@ import (
"github.com/spacemeshos/go-spacemesh/txs"
"github.com/spacemeshos/go-spacemesh/vm"
"github.com/spacemeshos/go-spacemesh/vm/core"
walletProgram "github.com/spacemeshos/go-spacemesh/vm/programs/wallet"
"github.com/spacemeshos/go-spacemesh/vm/sdk"
"github.com/spacemeshos/go-spacemesh/vm/sdk/wallet"
walletTemplate "github.com/spacemeshos/go-spacemesh/vm/templates/wallet"
)

func init() {
os.Setenv("ATHENA_LIB_PATH", "../../../build")
}

func TestTransactionService_List(t *testing.T) {
types.SetLayersPerEpoch(5)
db := statesql.InMemoryTest(t)
Expand Down Expand Up @@ -227,7 +234,7 @@ func TestTransactionService_EstimateGas(t *testing.T) {
t.Cleanup(cleanup)

keys := make([]signing.PrivateKey, 4)
accounts := make([]types.Account, len(keys))
accounts := make([]types.Account, len(keys)+1)
rng := rand.New(rand.NewSource(10101))
for i := range keys {
pub, priv, err := ed25519.GenerateKey(rng)
Expand All @@ -237,6 +244,11 @@ func TestTransactionService_EstimateGas(t *testing.T) {
require.NoError(t, err)
accounts[i] = types.Account{Address: address, Balance: 1e12}
}
accounts[len(keys)] = types.Account{
Address: walletTemplate.TemplateAddress,
State: walletProgram.PROGRAM,
TemplateAddress: &walletTemplate.TemplateAddress,
}
require.NoError(t, vminst.ApplyGenesis(accounts))
tx, err := wallet.Spawn(keys[0], 0)
require.NoError(t, err)
Expand All @@ -257,7 +269,7 @@ func TestTransactionService_EstimateGas(t *testing.T) {
Transaction: tx,
})
require.NoError(t, err)
require.Equal(t, uint64(36090), resp.RecommendedMaxGas)
require.Equal(t, uint64(20200), resp.RecommendedMaxGas)
})
t.Run("malformed tx", func(t *testing.T) {
_, err := client.EstimateGas(ctx, &spacemeshv2alpha1.EstimateGasRequest{
Expand Down Expand Up @@ -301,7 +313,7 @@ func TestTransactionService_ParseTransaction(t *testing.T) {
t.Cleanup(cleanup)

keys := make([]signing.PrivateKey, 4)
accounts := make([]types.Account, len(keys))
accounts := make([]types.Account, len(keys)+1)
rng := rand.New(rand.NewSource(10101))
for i := range keys {
pub, priv, err := ed25519.GenerateKey(rng)
Expand All @@ -311,6 +323,11 @@ func TestTransactionService_ParseTransaction(t *testing.T) {
require.NoError(t, err)
accounts[i] = types.Account{Address: addr, Balance: 1e12}
}
accounts[len(keys)] = types.Account{
Address: walletTemplate.TemplateAddress,
State: walletProgram.PROGRAM,
TemplateAddress: &walletTemplate.TemplateAddress,
}
require.NoError(t, vminst.ApplyGenesis(accounts))
tx, err := wallet.Spawn(keys[0], 0)
require.NoError(t, err)
Expand Down Expand Up @@ -397,8 +414,11 @@ func TestTransactionService_ParseTransaction(t *testing.T) {
})
require.NoError(t, err)

require.Equal(t, resp.Tx.Contents.GetSend().Amount, amount)
require.Equal(t, resp.Tx.Contents.GetSend().Destination, addr.String())
// TODO(lane): we don't currently parse tx amount for athena txs
require.Equal(t, uint64(0), resp.Tx.Contents.GetSend().Amount)
require.Equal(t, "", resp.Tx.Contents.GetSend().Destination)
// require.Equal(t, amount, resp.Tx.Contents.GetSend().Amount)
// require.Equal(t, addr.String(), resp.Tx.Contents.GetSend().Destination)
})

t.Run("transaction contents for spawn tx", func(t *testing.T) {
Expand All @@ -410,8 +430,13 @@ func TestTransactionService_ParseTransaction(t *testing.T) {
Transaction: tx,
Verify: true,
})
require.NoError(t, err)
require.Equal(t, resp.Tx.Contents.GetSingleSigSpawn().Pubkey, publicKey.String())

// in Spacemesh you can parse a spawn tx for an account that's already spawned.
// Athena doesn't allow this.
// require.NoError(t, err)
// require.Equal(t, publicKey.String(), resp.Tx.Contents.GetSingleSigSpawn().Pubkey)
require.Equal(t, codes.InvalidArgument, status.Code(err))
require.Nil(t, resp)
})
}

Expand Down

0 comments on commit bb5dc73

Please sign in to comment.