From 3ad1f007bffb8f322b8220cb3c0dd10bdd0b12d6 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 10 Feb 2023 13:03:50 +0100 Subject: [PATCH] itest: create copy before modifying mint request 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. --- itest/assets_test.go | 16 ++++++++++++++++ itest/reissuance_test.go | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/itest/assets_test.go b/itest/assets_test.go index 7c3131e15..1300ef7d3 100644 --- a/itest/assets_test.go +++ b/itest/assets_test.go @@ -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 ( @@ -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) diff --git a/itest/reissuance_test.go b/itest/reissuance_test.go index c483c590d..fef2fc2a2 100644 --- a/itest/reissuance_test.go +++ b/itest/reissuance_test.go @@ -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 @@ -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.