Skip to content

Commit

Permalink
itest: update default minted assets to use heterogeneous versions
Browse files Browse the repository at this point in the history
This also let's us test that we can: mint, create addrs for, and also
send v1 assets.
  • Loading branch information
Roasbeef committed Sep 28, 2023
1 parent a795fd7 commit a0a9705
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
13 changes: 11 additions & 2 deletions itest/addrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ func testAddresses(t *harnessTest) {
// In order to force a split, we don't try to send the full
// asset.
addr, err := secondTapd.NewAddr(ctxt, &taprpc.NewAddrRequest{
AssetId: a.AssetGenesis.AssetId,
Amt: a.Amount - 1,
AssetId: a.AssetGenesis.AssetId,
Amt: a.Amount - 1,
AssetVersion: a.Version,
})
require.NoError(t.t, err)
addresses = append(addresses, addr)
Expand Down Expand Up @@ -99,10 +100,16 @@ func testAddresses(t *harnessTest) {
ctxt, &taprpc.ListTransfersRequest{},
)
require.NoError(t.t, err)

require.Len(t.t, resp.Transfers, len(rpcAssets))
require.Len(t.t, resp.Transfers[0].Outputs, 2)

firstOut := resp.Transfers[0].Outputs[0]
require.EqualValues(t.t, 1, firstOut.Amount)
require.Equal(
t.t, addresses[0].AssetVersion, firstOut.AssetVersion,
)

firstIn := resp.Transfers[0].Inputs[0]
require.Equal(
t.t, rpcAssets[0].AssetGenesis.AssetId, firstIn.AssetId,
Expand Down Expand Up @@ -268,8 +275,10 @@ func runMultiSendTest(ctxt context.Context, t *harnessTest, alice,

transfer := resp.Transfers[runIdx]
require.Len(t.t, transfer.Outputs, numOutputs)

firstOut := transfer.Outputs[0]
require.EqualValues(t.t, changeAmt, firstOut.Amount)

firstIn := transfer.Inputs[0]
require.Equal(t.t, genInfo.AssetId, firstIn.AssetId)

Expand Down
13 changes: 13 additions & 0 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ func AssetScriptKeyIsBurnCheck(isBurn bool) AssetCheck {
}
}

// AssetVersionCheck returns a check function that tests an asset's version.
func AssetVersionCheck(version taprpc.AssetVersion) AssetCheck {
return func(a *taprpc.Asset) error {
if a.Version != a.Version {
return fmt.Errorf("unexpected asset version, got %v "+
"wanted %v", a.Version, version)
}

return nil
}
}

// GroupAssetsByName converts an unordered list of assets to a map of lists of
// assets, where all assets in a list have the same name.
func GroupAssetsByName(assets []*taprpc.Asset) map[string][]*taprpc.Asset {
Expand Down Expand Up @@ -681,6 +693,7 @@ func AssertNonInteractiveRecvComplete(t *testing.T,
func AssertAddr(t *testing.T, expected *taprpc.Asset, actual *taprpc.Addr) {
require.Equal(t, expected.AssetGenesis.AssetId, actual.AssetId)
require.Equal(t, expected.AssetType, actual.AssetType)
require.Equal(t, expected.Version, actual.AssetVersion)

if expected.AssetGroup == nil {
require.Nil(t, actual.GroupKey)
Expand Down
12 changes: 8 additions & 4 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var (
AssetMeta: &taprpc.AssetMeta{
Data: []byte("some metadata"),
},
Amount: 5000,
Amount: 5000,
AssetVersion: taprpc.AssetVersion_ASSET_VERSION_V0,
},
},
{
Expand All @@ -34,7 +35,8 @@ var (
AssetMeta: &taprpc.AssetMeta{
Data: []byte("some metadata"),
},
Amount: 1,
Amount: 1,
AssetVersion: taprpc.AssetVersion_ASSET_VERSION_V1,
},
},
}
Expand All @@ -46,7 +48,8 @@ var (
AssetMeta: &taprpc.AssetMeta{
Data: []byte("some metadata"),
},
Amount: 5000,
Amount: 5000,
AssetVersion: taprpc.AssetVersion_ASSET_VERSION_V1,
},
EnableEmission: true,
},
Expand All @@ -57,7 +60,8 @@ var (
AssetMeta: &taprpc.AssetMeta{
Data: []byte("some metadata"),
},
Amount: 1,
Amount: 1,
AssetVersion: taprpc.AssetVersion_ASSET_VERSION_V0,
},
EnableEmission: true,
},
Expand Down
1 change: 1 addition & 0 deletions itest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func MintAssetUnconfirmed(t *testing.T, minerClient *rpcclient.Client,
AssetTypeCheck(assetRequest.Asset.AssetType),
AssetAnchorCheck(*hashes[0], zeroHash),
AssetScriptKeyIsLocalCheck(true),
AssetVersionCheck(assetRequest.Asset.AssetVersion),
)
}

Expand Down

0 comments on commit a0a9705

Please sign in to comment.