Skip to content

Commit

Permalink
add multiple transfers in 1 tx
Browse files Browse the repository at this point in the history
  • Loading branch information
wlawt committed Apr 29, 2024
1 parent ea3d232 commit b4c0d7c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
5 changes: 3 additions & 2 deletions chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,9 @@ func (t *Transaction) Execute(
refund := maxFee - feeRequired
if refund > 0 {
ts.DisableAllocation()
defer ts.EnableAllocation()
if err := s.Refund(ctx, t.Auth.Sponsor(), ts, refund); err != nil {
err = s.Refund(ctx, t.Auth.Sponsor(), ts, refund)
ts.EnableAllocation()
if err != nil {
return handleRevert(err)
}
}
Expand Down
53 changes: 52 additions & 1 deletion examples/tokenvm/tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func init() {
flag.IntVar(
&vms,
"vms",
3,
4,
"number of VMs to create",
)
}
Expand All @@ -101,6 +101,11 @@ var (
rsender2 codec.Address
sender2 string

priv3 ed25519.PrivateKey
factory3 *auth.ED25519Factory
rsender3 codec.Address
sender3 string

asset1 []byte
asset1Symbol []byte
asset1Decimals uint8
Expand Down Expand Up @@ -161,6 +166,17 @@ var _ = ginkgo.BeforeSuite(func() {
zap.String("pk", hex.EncodeToString(priv2[:])),
)

priv3, err = ed25519.GeneratePrivateKey()
gomega.Ω(err).Should(gomega.BeNil())
factory3 = auth.NewED25519Factory(priv3)
rsender3 = auth.NewED25519Address(priv3.PublicKey())
sender3 = codec.MustAddressBech32(tconsts.HRP, rsender3)
log.Debug(
"generated key",
zap.String("addr", sender3),
zap.String("pk", hex.EncodeToString(priv3[:])),
)

asset1 = []byte("1")
asset1Symbol = []byte("s1")
asset1Decimals = uint8(1)
Expand Down Expand Up @@ -1648,6 +1664,41 @@ var _ = ginkgo.Describe("[Tx Processing]", func() {
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(orders).Should(gomega.HaveLen(0))
})

ginkgo.It("transfer to multiple accounts in a single tx", func() {
parser, err := instances[3].tcli.Parser(context.Background())
gomega.Ω(err).Should(gomega.BeNil())
submit, _, _, err := instances[3].cli.GenerateTransaction(
context.Background(),
parser,
[]chain.Action{
&actions.Transfer{
To: rsender2,
Value: 101,
},
&actions.Transfer{
To: rsender3,
Value: 50,
},
},
factory,
)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(submit(context.Background())).Should(gomega.BeNil())
time.Sleep(2 * time.Second) // for replay test
accept := expectBlk(instances[3])
results := accept(false)
gomega.Ω(results).Should(gomega.HaveLen(1))
gomega.Ω(results[0].Success).Should(gomega.BeTrue())

balance2, err := instances[3].tcli.Balance(context.Background(), sender2, codec.EmptyAddress)
gomega.Ω(err).To(gomega.BeNil())
gomega.Ω(balance2).To(gomega.Equal(uint64(101)))

balance3, err := instances[3].tcli.Balance(context.Background(), sender3, codec.EmptyAddress)
gomega.Ω(err).To(gomega.BeNil())
gomega.Ω(balance3).To(gomega.Equal(uint64(50)))
})
})

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

0 comments on commit b4c0d7c

Please sign in to comment.