Skip to content

Commit

Permalink
add create and mint multiple assets
Browse files Browse the repository at this point in the history
  • Loading branch information
wlawt committed Apr 30, 2024
1 parent b4c0d7c commit 40c0529
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/tokenvm/actions/mint_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type MintAsset struct {
// To is the recipient of the [Value].
To codec.Address `json:"to"`

// Asset is the [TxID] that created the asset.
// Asset is the [ActionID] that created the asset.
Asset codec.LID `json:"asset"`

// Number of assets to mint to [To].
Expand Down
2 changes: 1 addition & 1 deletion examples/tokenvm/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Default() *Genesis {
StorageValueWriteUnits: 3,

// Action Per Tx
MaxActionsPerTx: 2,
MaxActionsPerTx: 10,
}
}

Expand Down
123 changes: 123 additions & 0 deletions examples/tokenvm/tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ var (
asset3Symbol []byte
asset3Decimals uint8
asset3ID codec.LID
asset4 []byte
asset4Symbol []byte
asset4Decimals uint8
asset4ID codec.LID

// when used with embedded VMs
genesisBytes []byte
Expand Down Expand Up @@ -186,6 +190,9 @@ var _ = ginkgo.BeforeSuite(func() {
asset3 = []byte("3")
asset3Symbol = []byte("s3")
asset3Decimals = uint8(3)
asset4 = []byte("4")
asset4Symbol = []byte("s4")
asset4Decimals = uint8(4)

// create embedded VMs
instances = make([]instance, vms)
Expand Down Expand Up @@ -1699,6 +1706,122 @@ var _ = ginkgo.Describe("[Tx Processing]", func() {
gomega.Ω(err).To(gomega.BeNil())
gomega.Ω(balance3).To(gomega.Equal(uint64(50)))
})

ginkgo.It("create and mint multiple of assets in a single tx", func() {
// Create asset
parser, err := instances[3].tcli.Parser(context.Background())
gomega.Ω(err).Should(gomega.BeNil())
submit, tx, _, err := instances[3].cli.GenerateTransaction(
context.Background(),
parser,
[]chain.Action{
&actions.CreateAsset{
Symbol: asset1Symbol,
Decimals: asset1Decimals,
Metadata: asset1,
},
&actions.CreateAsset{
Symbol: asset2Symbol,
Decimals: asset2Decimals,
Metadata: asset2,
},
&actions.CreateAsset{
Symbol: asset3Symbol,
Decimals: asset3Decimals,
Metadata: asset3,
},
&actions.CreateAsset{
Symbol: asset4Symbol,
Decimals: asset4Decimals,
Metadata: asset4,
},
},
factory,
)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(submit(context.Background())).Should(gomega.BeNil())
accept := expectBlk(instances[3])
results := accept(true)
gomega.Ω(results).Should(gomega.HaveLen(1))
gomega.Ω(results[0].Success).Should(gomega.BeTrue())

asset1ID = codec.CreateLID(0, tx.ID())
asset2ID = codec.CreateLID(1, tx.ID())
asset3ID = codec.CreateLID(2, tx.ID())
asset4ID = codec.CreateLID(3, tx.ID())

// Mint multiple
submit, _, _, err = instances[3].cli.GenerateTransaction(
context.Background(),
parser,
[]chain.Action{
&actions.MintAsset{
To: rsender2,
Asset: asset1ID,
Value: 10,
},
&actions.MintAsset{
To: rsender2,
Asset: asset2ID,
Value: 10,
},
&actions.MintAsset{
To: rsender2,
Asset: asset3ID,
Value: 10,
},
&actions.MintAsset{
To: rsender2,
Asset: asset4ID,
Value: 10,
},
&actions.MintAsset{
To: rsender3,
Asset: asset1ID,
Value: 10,
},
&actions.MintAsset{
To: rsender3,
Asset: asset2ID,
Value: 10,
},
&actions.MintAsset{
To: rsender3,
Asset: asset3ID,
Value: 10,
},
&actions.MintAsset{
To: rsender3,
Asset: asset4ID,
Value: 10,
},
},
factory,
)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(submit(context.Background())).Should(gomega.BeNil())
accept = expectBlk(instances[3])
results = accept(true)
gomega.Ω(results).Should(gomega.HaveLen(1))
gomega.Ω(results[0].Success).Should(gomega.BeTrue())

// check sender2 assets
balance1, err := instances[3].tcli.Balance(context.TODO(), sender2, asset1ID)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(balance1).Should(gomega.Equal(uint64(10)))

balance2, err := instances[3].tcli.Balance(context.TODO(), sender2, asset2ID)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(balance2).Should(gomega.Equal(uint64(10)))

balance3, err := instances[3].tcli.Balance(context.TODO(), sender2, asset3ID)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(balance3).Should(gomega.Equal(uint64(10)))

balance4, err := instances[3].tcli.Balance(context.TODO(), sender2, asset4ID)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(balance4).Should(gomega.Equal(uint64(10)))
})
})

func expectBlk(i instance) func(bool) []*chain.Result {
Expand Down

0 comments on commit 40c0529

Please sign in to comment.