Skip to content

Commit

Permalink
itest: create copy before modifying mint request
Browse files Browse the repository at this point in the history
This fixes an issue with the itest that the requests were modified in
place, affecting the next test that's being run.
By copying the request before modifying it, this can be avoided.
  • Loading branch information
guggero committed Feb 22, 2023
1 parent 3ec35c6 commit f9f6d94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/lightninglabs/taro/tarorpc"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/proto"
)

var (
Expand Down Expand Up @@ -47,6 +48,21 @@ var (
}
)

// copyRequest is a helper function to copy a request so that we can modify it.
func copyRequest(req *tarorpc.MintAssetRequest) *tarorpc.MintAssetRequest {
return proto.Clone(req).(*tarorpc.MintAssetRequest)
}

// copyRequests is a helper function to copy a slice of requests so that we can
// modify them.
func copyRequests(reqs []*tarorpc.MintAssetRequest) []*tarorpc.MintAssetRequest {
copied := make([]*tarorpc.MintAssetRequest, len(reqs))
for idx := range reqs {
copied[idx] = copyRequest(reqs[idx])
}
return copied
}

func mintAssets(t *harnessTest) {
rpcSimpleAssets := mintAssetsConfirmBatch(t, t.tarod, simpleAssets)
rpcIssuableAssets := mintAssetsConfirmBatch(t, t.tarod, issuableAssets)
Expand Down
4 changes: 2 additions & 2 deletions itest/reissuance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func testReissuance(t *harnessTest) {

// Reissue one more collectible and half the original mint amount for
// the normal asset.
reissuedAssets := simpleAssets
reissuedAssets := copyRequests(simpleAssets)

reissuedAssets[0].Amount = normalGroupMintHalf
reissuedAssets[0].GroupKey = normalGroupKey
Expand Down Expand Up @@ -207,7 +207,7 @@ func testMintWithGroupKeyErrors(t *harnessTest) {

// Now, create a minting request to try and reissue into the group
// created during minting.
reissueRequest := simpleAssets[0]
reissueRequest := copyRequest(simpleAssets[0])
reissueRequest.GroupKey = collectGroupKey

// A request must not have the emission flag set if a group key is given.
Expand Down

0 comments on commit f9f6d94

Please sign in to comment.