mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00

* * added creation of random machines to prepare a test case * setting all the consensus timeout values at once (if changed) * mutex protection of the elements tx crafting methods (sequential processing) * Extending the TestMachineNFTIssuance test case to parallel threads and threading issues * moving all elements-rpc usage to the elementd-connector.go file * removed call to fatal * added WaitForNextBlock to be out of sync with PoP to avoid the following error PoP broadcast tx failed: node0.info: key not found after the test --------- Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package util_test
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"math/rand"
|
|
"strconv"
|
|
"sync"
|
|
"testing"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/planetmint/planetmint-go/testutil/keeper"
|
|
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
|
"github.com/planetmint/planetmint-go/util"
|
|
"github.com/planetmint/planetmint-go/util/mocks"
|
|
"github.com/planetmint/planetmint-go/x/machine/types"
|
|
elements "github.com/rddl-network/elements-rpc"
|
|
elementsmocks "github.com/rddl-network/elements-rpc/utils/mocks"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRegisterNFT(t *testing.T) {
|
|
params := types.DefaultParams()
|
|
url := params.AssetRegistryScheme + "://" + params.AssetRegistryDomain + "/" + params.AssetRegistryPath
|
|
entity := types.Entity{
|
|
Domain: params.AssetRegistryDomain,
|
|
}
|
|
c := types.Contract{
|
|
Entity: entity,
|
|
IssuerPubkey: "020000000000000000000000000000000000000000000000000000000000000000",
|
|
MachineAddr: "plmnt10mq5nj8jhh27z7ejnz2ql3nh0qhzjnfvy50877",
|
|
Name: "machine",
|
|
Precision: 0,
|
|
Version: 0,
|
|
}
|
|
contractBytes, err := json.Marshal(c)
|
|
assert.NoError(t, err)
|
|
|
|
contract := string(contractBytes)
|
|
asset := "0000000000000000000000000000000000000000000000000000000000000000"
|
|
goctx := context.Background()
|
|
|
|
util.RegisterAssetServiceHTTPClient = &mocks.MockClient{}
|
|
err = util.RegisterAsset(goctx, asset, contract, url)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestMachineNFTIssuance(t *testing.T) {
|
|
elements.Client = &elementsmocks.MockClient{}
|
|
util.RegisterAssetServiceHTTPClient = &mocks.MockClient{}
|
|
_, ctx := keeper.MachineKeeper(t)
|
|
params := types.DefaultParams()
|
|
var wg sync.WaitGroup
|
|
|
|
for i := 0; i < 10; i++ {
|
|
wg.Add(1)
|
|
go func() {
|
|
randomInt := rand.Int()
|
|
sk, pk := sample.KeyPair(randomInt)
|
|
machine := moduleobject.MachineRandom(pk, pk, sk, "address "+strconv.Itoa(randomInt), randomInt)
|
|
goCtx := sdk.WrapSDKContext(ctx)
|
|
|
|
err := util.IssueMachineNFT(goCtx, &machine, params.AssetRegistryScheme, params.AssetRegistryDomain, params.AssetRegistryPath)
|
|
assert.NoError(t, err)
|
|
wg.Done()
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
}
|