Skip to content

Commit

Permalink
fix tokenvm
Browse files Browse the repository at this point in the history
  • Loading branch information
wlawt committed Apr 23, 2024
1 parent 1cb8180 commit 975ac21
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 74 deletions.
8 changes: 4 additions & 4 deletions cli/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (h *Handler) Spam(
return err
}
action := getTransfer(keys[0].Address, 0)
maxUnits, err := chain.EstimateMaxUnits(parser.Rules(time.Now().UnixMilli()), action, factory, nil)
maxUnits, err := chain.EstimateMaxUnits(parser.Rules(time.Now().UnixMilli()), action, factory)
if err != nil {
return err
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func (h *Handler) Spam(
accounts[i] = pk

// Send funds
_, tx, err := cli.GenerateTransactionManual(parser, nil, getTransfer(pk.Address, distAmount), factory, feePerTx)
_, tx, err := cli.GenerateTransactionManual(parser, getTransfer(pk.Address, distAmount), factory, feePerTx)
if err != nil {
return err
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func (h *Handler) Spam(
if maxFee != nil {
fee = *maxFee
}
_, tx, err := issuer.c.GenerateTransactionManual(parser, nil, action, factory, fee, tm)
_, tx, err := issuer.c.GenerateTransactionManual(parser, action, factory, fee, tm)
if err != nil {
utils.Outf("{{orange}}failed to generate tx:{{/}} %v\n", err)
continue
Expand Down Expand Up @@ -424,7 +424,7 @@ func (h *Handler) Spam(
if err != nil {
return err
}
_, tx, err := cli.GenerateTransactionManual(parser, nil, getTransfer(key.Address, returnAmt), f, feePerTx)
_, tx, err := cli.GenerateTransactionManual(parser, getTransfer(key.Address, returnAmt), f, feePerTx)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions examples/tokenvm/cmd/token-cli/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var fundFaucetCmd = &cobra.Command{
if err != nil {
return err
}
if _, _, err = sendAndWait(ctx, nil, &actions.Transfer{
if _, _, err = sendAndWait(ctx, &actions.Transfer{
To: addr,
Asset: ids.Empty,
Value: amount,
Expand Down Expand Up @@ -126,7 +126,7 @@ var transferCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.Transfer{
_, _, err = sendAndWait(ctx, &actions.Transfer{
To: recipient,
Asset: assetID,
Value: amount,
Expand Down Expand Up @@ -169,7 +169,7 @@ var createAssetCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.CreateAsset{
_, _, err = sendAndWait(ctx, &actions.CreateAsset{
Symbol: []byte(symbol),
Decimals: uint8(decimals), // already constrain above to prevent overflow
Metadata: []byte(metadata),
Expand Down Expand Up @@ -233,7 +233,7 @@ var mintAssetCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.MintAsset{
_, _, err = sendAndWait(ctx, &actions.MintAsset{
Asset: assetID,
To: recipient,
Value: amount,
Expand Down Expand Up @@ -270,7 +270,7 @@ var closeOrderCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.CloseOrder{
_, _, err = sendAndWait(ctx, &actions.CloseOrder{
Order: orderID,
Out: outAssetID,
}, cli, scli, tcli, factory, true)
Expand Down Expand Up @@ -356,7 +356,7 @@ var createOrderCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.CreateOrder{
_, _, err = sendAndWait(ctx, &actions.CreateOrder{
In: inAssetID,
InTick: inTick,
Out: outAssetID,
Expand Down Expand Up @@ -473,7 +473,7 @@ var fillOrderCmd = &cobra.Command{
if err != nil {
return err
}
_, _, err = sendAndWait(ctx, nil, &actions.FillOrder{
_, _, err = sendAndWait(ctx, &actions.FillOrder{
Order: order.ID,
Owner: owner,
In: inAssetID,
Expand Down
52 changes: 26 additions & 26 deletions examples/tokenvm/cmd/token-wallet/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (b *Backend) collectBlocks() {
continue
}

_, symbol, decimals, _, _, owner, _, err := b.tcli.Asset(b.ctx, action.Asset, true)
_, symbol, decimals, _, _, owner, err := b.tcli.Asset(b.ctx, action.Asset, true)
if err != nil {
b.fatal(err)
return
Expand Down Expand Up @@ -309,7 +309,7 @@ func (b *Backend) collectBlocks() {
continue
}

_, symbol, decimals, _, _, owner, _, err := b.tcli.Asset(b.ctx, action.Asset, true)
_, symbol, decimals, _, _, owner, err := b.tcli.Asset(b.ctx, action.Asset, true)
if err != nil {
b.fatal(err)
return
Expand Down Expand Up @@ -361,12 +361,12 @@ func (b *Backend) collectBlocks() {
continue
}

_, inSymbol, inDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, action.In, true)
_, inSymbol, inDecimals, _, _, _, err := b.tcli.Asset(b.ctx, action.In, true)
if err != nil {
b.fatal(err)
return
}
_, outSymbol, outDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, action.Out, true)
_, outSymbol, outDecimals, _, _, _, err := b.tcli.Asset(b.ctx, action.Out, true)
if err != nil {
b.fatal(err)
return
Expand Down Expand Up @@ -402,12 +402,12 @@ func (b *Backend) collectBlocks() {
continue
}

_, inSymbol, inDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, action.In, true)
_, inSymbol, inDecimals, _, _, _, err := b.tcli.Asset(b.ctx, action.In, true)
if err != nil {
b.fatal(err)
return
}
_, outSymbol, outDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, action.Out, true)
_, outSymbol, outDecimals, _, _, _, err := b.tcli.Asset(b.ctx, action.Out, true)
if err != nil {
b.fatal(err)
return
Expand Down Expand Up @@ -608,7 +608,7 @@ func (b *Backend) GetMyAssets() []*AssetInfo {
if !owned[i] {
continue
}
_, symbol, decimals, metadata, supply, owner, _, err := b.tcli.Asset(b.ctx, asset, false)
_, symbol, decimals, metadata, supply, owner, err := b.tcli.Asset(b.ctx, asset, false)
if err != nil {
b.fatal(err)
return nil
Expand Down Expand Up @@ -639,7 +639,7 @@ func (b *Backend) CreateAsset(symbol string, decimals string, metadata string) e
if err != nil {
return err
}
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, nil, &actions.CreateAsset{
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, &actions.CreateAsset{
Symbol: []byte(symbol),
Decimals: uint8(udecimals),
Metadata: []byte(metadata),
Expand Down Expand Up @@ -674,7 +674,7 @@ func (b *Backend) MintAsset(asset string, address string, amount string) error {
if err != nil {
return err
}
_, _, decimals, _, _, _, _, err := b.tcli.Asset(b.ctx, assetID, true)
_, _, decimals, _, _, _, err := b.tcli.Asset(b.ctx, assetID, true)
if err != nil {
return err
}
Expand All @@ -694,7 +694,7 @@ func (b *Backend) MintAsset(asset string, address string, amount string) error {
}

// Generate transaction
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, nil, &actions.MintAsset{
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, &actions.MintAsset{
To: to,
Asset: assetID,
Value: value,
Expand Down Expand Up @@ -729,7 +729,7 @@ func (b *Backend) Transfer(asset string, address string, amount string, memo str
if err != nil {
return err
}
_, symbol, decimals, _, _, _, _, err := b.tcli.Asset(b.ctx, assetID, true)
_, symbol, decimals, _, _, _, err := b.tcli.Asset(b.ctx, assetID, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -758,7 +758,7 @@ func (b *Backend) Transfer(asset string, address string, amount string, memo str
}

// Generate transaction
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, nil, &actions.Transfer{
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, &actions.Transfer{
To: to,
Asset: assetID,
Value: value,
Expand Down Expand Up @@ -805,7 +805,7 @@ func (b *Backend) GetBalance() ([]*BalanceInfo, error) {
}
balances := []*BalanceInfo{}
for _, asset := range assets {
_, symbol, decimals, _, _, _, _, err := b.tcli.Asset(b.ctx, asset, true)
_, symbol, decimals, _, _, _, err := b.tcli.Asset(b.ctx, asset, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -937,7 +937,7 @@ func (b *Backend) GetAllAssets() []*AssetInfo {
}
assets := []*AssetInfo{}
for _, asset := range arr {
_, symbol, decimals, metadata, supply, owner, _, err := b.tcli.Asset(b.ctx, asset, false)
_, symbol, decimals, metadata, supply, owner, err := b.tcli.Asset(b.ctx, asset, false)
if err != nil {
b.fatal(err)
return nil
Expand Down Expand Up @@ -968,7 +968,7 @@ func (b *Backend) AddAsset(asset string) error {
if hasAsset {
return nil
}
exists, _, _, _, _, owner, _, err := b.tcli.Asset(b.ctx, assetID, true)
exists, _, _, _, _, owner, err := b.tcli.Asset(b.ctx, assetID, true)
if err != nil {
return err
}
Expand All @@ -993,12 +993,12 @@ func (b *Backend) GetMyOrders() ([]*Order, error) {
continue
}
inID := order.InAsset
_, inSymbol, inDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, inID, true)
_, inSymbol, inDecimals, _, _, _, err := b.tcli.Asset(b.ctx, inID, true)
if err != nil {
return nil, err
}
outID := order.OutAsset
_, outSymbol, outDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, outID, true)
_, outSymbol, outDecimals, _, _, _, err := b.tcli.Asset(b.ctx, outID, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1035,7 +1035,7 @@ func (b *Backend) GetOrders(pair string) ([]*Order, error) {
if err != nil {
return nil, err
}
_, inSymbol, inDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, inID, true)
_, inSymbol, inDecimals, _, _, _, err := b.tcli.Asset(b.ctx, inID, true)
if err != nil {
return nil, err
}
Expand All @@ -1044,7 +1044,7 @@ func (b *Backend) GetOrders(pair string) ([]*Order, error) {
if err != nil {
return nil, err
}
_, outSymbol, outDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, outID, true)
_, outSymbol, outDecimals, _, _, _, err := b.tcli.Asset(b.ctx, outID, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1080,11 +1080,11 @@ func (b *Backend) CreateOrder(assetIn string, inTick string, assetOut string, ou
if err != nil {
return err
}
_, _, inDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, inID, true)
_, _, inDecimals, _, _, _, err := b.tcli.Asset(b.ctx, inID, true)
if err != nil {
return err
}
_, outSymbol, outDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, outID, true)
_, outSymbol, outDecimals, _, _, _, err := b.tcli.Asset(b.ctx, outID, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -1112,7 +1112,7 @@ func (b *Backend) CreateOrder(assetIn string, inTick string, assetOut string, ou
}

// Generate transaction
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, nil, &actions.CreateOrder{
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, &actions.CreateOrder{
In: inID,
InTick: iTick,
Out: outID,
Expand Down Expand Up @@ -1171,7 +1171,7 @@ func (b *Backend) FillOrder(orderID string, orderOwner string, assetIn string, i
if err != nil {
return err
}
_, inSymbol, inDecimals, _, _, _, _, err := b.tcli.Asset(b.ctx, inID, true)
_, inSymbol, inDecimals, _, _, _, err := b.tcli.Asset(b.ctx, inID, true)
if err != nil {
return err
}
Expand All @@ -1198,7 +1198,7 @@ func (b *Backend) FillOrder(orderID string, orderOwner string, assetIn string, i
}

// Generate transaction
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, nil, &actions.FillOrder{
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, &actions.FillOrder{
Order: oID,
Owner: owner,
In: inID,
Expand Down Expand Up @@ -1255,7 +1255,7 @@ func (b *Backend) CloseOrder(orderID string, assetOut string) error {
}

// Generate transaction
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, nil, &actions.CloseOrder{
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, &actions.CloseOrder{
Order: oID,
Out: outID,
}, b.factory)
Expand Down Expand Up @@ -1395,7 +1395,7 @@ func (b *Backend) Message(message string, url string) error {
}

// Generate transaction
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, nil, &actions.Transfer{
_, tx, maxFee, err := b.cli.GenerateTransaction(b.ctx, b.parser, &actions.Transfer{
To: recipientAddr,
Asset: ids.Empty,
Value: fee,
Expand Down
37 changes: 0 additions & 37 deletions examples/tokenvm/tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -1684,42 +1683,6 @@ func expectBlk(i instance) func(bool) []*chain.Result {
}
}

// TODO: unify with expectBlk
func expectBlkWithContext(i instance) func(bool) []*chain.Result {
ctx := context.TODO()

// manually signal ready
gomega.Ω(i.vm.Builder().Force(ctx)).To(gomega.BeNil())
// manually ack ready sig as in engine
<-i.toEngine

bctx := &block.Context{PChainHeight: 1}
blk, err := i.vm.BuildBlockWithContext(ctx, bctx)
gomega.Ω(err).To(gomega.BeNil())
gomega.Ω(blk).To(gomega.Not(gomega.BeNil()))
cblk := blk.(block.WithVerifyContext)

gomega.Ω(cblk.VerifyWithContext(ctx, bctx)).To(gomega.BeNil())
gomega.Ω(blk.Status()).To(gomega.Equal(choices.Processing))

err = i.vm.SetPreference(ctx, blk.ID())
gomega.Ω(err).To(gomega.BeNil())

return func(add bool) []*chain.Result {
gomega.Ω(blk.Accept(ctx)).To(gomega.BeNil())
gomega.Ω(blk.Status()).To(gomega.Equal(choices.Accepted))

if add {
blocks = append(blocks, blk)
}

lastAccepted, err := i.vm.LastAccepted(ctx)
gomega.Ω(err).To(gomega.BeNil())
gomega.Ω(lastAccepted).To(gomega.Equal(blk.ID()))
return blk.(*chain.StatelessBlock).Results()
}
}

var _ common.AppSender = &appSender{}

type appSender struct {
Expand Down

0 comments on commit 975ac21

Please sign in to comment.