From a96eba5f27d59e393abe32c886ca2cb64c2ce128 Mon Sep 17 00:00:00 2001 From: janniks Date: Mon, 11 Mar 2024 14:43:50 +0100 Subject: [PATCH] test: update bns tests --- packages/bns/src/index.ts | 52 +++++++++--------- packages/bns/tests/bns.test.ts | 54 +++++++++---------- .../wallet-sdk/tests/models/profile.test.ts | 4 +- 3 files changed, 50 insertions(+), 60 deletions(-) diff --git a/packages/bns/src/index.ts b/packages/bns/src/index.ts index 303539bf0..c44a52476 100644 --- a/packages/bns/src/index.ts +++ b/packages/bns/src/index.ts @@ -1,39 +1,35 @@ import { ApiParam, IntegerType, utf8ToBytes } from '@stacks/common'; +import { ChainId, StacksNetwork } from '@stacks/network'; import { + AddressVersion, AnchorMode, - bufferCV, - callReadOnlyFunction, ClarityType, ClarityValue, + FungibleConditionCode, + NonFungibleConditionCode, + PostCondition, + ResponseErrorCV, + StacksTransaction, + UnsignedContractCallOptions, + bufferCV, + bufferCVFromString, + callReadOnlyFunction, + createNonFungiblePostCondition, + createSTXPostCondition, cvToString, getAddressFromPrivateKey, getCVTypeString, hash160, makeRandomPrivKey, makeUnsignedContractCall, - privateKeyToString, - ResponseErrorCV, - StacksTransaction, - standardPrincipalCV, - uintCV, - someCV, noneCV, - UnsignedContractCallOptions, - PostCondition, - createSTXPostCondition, - createStacksPublicKey, - publicKeyToAddress, - FungibleConditionCode, - AddressVersion, - createNonFungiblePostCondition, - NonFungibleConditionCode, parseAssetInfoString, + publicKeyToAddress, + someCV, + standardPrincipalCV, tupleCV, - bufferCVFromString, + uintCV, } from '@stacks/transactions'; - -import { ChainId, StacksNetwork } from '@stacks/network'; - import { decodeFQN, getZonefileHash } from './utils'; export const BNS_CONTRACT_NAME = 'bns'; @@ -154,7 +150,7 @@ export async function canRegisterName({ // Create a random address as input to read-only function call // Not used by BNS contract function but required by core node API // https://github.com/blockstack/stacks-blockchain/blob/master/src/net/http.rs#L1796 - const randomPrivateKey = privateKeyToString(makeRandomPrivKey()); + const randomPrivateKey = makeRandomPrivKey(); const randomAddress = getAddressFromPrivateKey(randomPrivateKey); return callReadOnlyBnsFunction({ @@ -199,7 +195,7 @@ export async function getNamespacePrice({ // Create a random address as input to read-only function call // Not used by BNS contract function but required by core node API // https://github.com/blockstack/stacks-blockchain/blob/master/src/net/http.rs#L1796 - const randomPrivateKey = privateKeyToString(makeRandomPrivKey()); + const randomPrivateKey = makeRandomPrivKey(); const randomAddress = getAddressFromPrivateKey(randomPrivateKey); return callReadOnlyBnsFunction({ @@ -254,7 +250,7 @@ export async function getNamePrice({ // Create a random address as input to read-only function call // Not used by BNS contract function but required by core node API // https://github.com/blockstack/stacks-blockchain/blob/master/src/net/http.rs#L1796 - const randomPrivateKey = privateKeyToString(makeRandomPrivKey()); + const randomPrivateKey = makeRandomPrivKey(); const randomAddress = getAddressFromPrivateKey(randomPrivateKey); return callReadOnlyBnsFunction({ @@ -315,7 +311,7 @@ export async function buildPreorderNamespaceTx({ const hashedSaltedNamespace = hash160(saltedNamespaceBytes); const burnSTXPostCondition = createSTXPostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), FungibleConditionCode.Equal, stxToBurn ); @@ -538,7 +534,7 @@ export async function buildPreorderNameTx({ const hashedSaltedName = hash160(saltedNamesBytes); const burnSTXPostCondition = createSTXPostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), FungibleConditionCode.Equal, stxToBurn ); @@ -707,7 +703,7 @@ export async function buildTransferNameTx({ zonefile ? someCV(bufferCV(getZonefileHash(zonefile))) : noneCV(), ]; const postConditionSender = createNonFungiblePostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), NonFungibleConditionCode.Sends, parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), tupleCV({ @@ -827,7 +823,7 @@ export async function buildRenewNameTx({ zonefile ? someCV(bufferCV(getZonefileHash(zonefile))) : noneCV(), ]; const burnSTXPostCondition = createSTXPostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), FungibleConditionCode.Equal, stxToBurn ); diff --git a/packages/bns/tests/bns.test.ts b/packages/bns/tests/bns.test.ts index 85b117bb8..4531d8941 100644 --- a/packages/bns/tests/bns.test.ts +++ b/packages/bns/tests/bns.test.ts @@ -1,37 +1,31 @@ -import fetchMock from 'jest-fetch-mock'; - +import { utf8ToBytes } from '@stacks/common'; +import { ChainId, STACKS_TESTNET, StacksNetwork } from '@stacks/network'; import { - responseOkCV, - responseErrorCV, - trueCV, - falseCV, - uintCV, - bufferCV, - hash160, - standardPrincipalCV, - noneCV, + AddressVersion, AnchorMode, - someCV, - createSTXPostCondition, - publicKeyToAddress, - createStacksPublicKey, FungibleConditionCode, - AddressVersion, - createNonFungiblePostCondition, NonFungibleConditionCode, + bufferCV, + bufferCVFromString, + createNonFungiblePostCondition, + createSTXPostCondition, + falseCV, + hash160, + noneCV, parseAssetInfoString, + publicKeyToAddress, + responseErrorCV, + responseOkCV, + someCV, + standardPrincipalCV, + trueCV, tupleCV, - bufferCVFromString, + uintCV, } from '@stacks/transactions'; - -import { ChainId, STACKS_TESTNET, StacksNetwork } from '@stacks/network'; - +import fetchMock from 'jest-fetch-mock'; import { BNS_CONTRACT_NAME, BnsContractAddress, PriceFunction } from '../src'; - import { decodeFQN, getZonefileHash } from '../src/utils'; -import { utf8ToBytes } from '@stacks/common'; - beforeEach(() => { fetchMock.resetMocks(); jest.resetModules(); @@ -338,7 +332,7 @@ test('preorderNamespace', async () => { const bnsFunctionName = 'namespace-preorder'; const burnSTXPostCondition = createSTXPostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), FungibleConditionCode.Equal, stxToBurn ); @@ -562,7 +556,7 @@ test('preorderName', async () => { const bnsFunctionName = 'name-preorder'; const burnSTXPostCondition = createSTXPostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), FungibleConditionCode.Equal, stxToBurn ); @@ -708,7 +702,7 @@ test('transferName', async () => { const { namespace, name } = decodeFQN(fullyQualifiedName); const nameTransferPostConditionOne = createNonFungiblePostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), NonFungibleConditionCode.Sends, parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), tupleCV({ @@ -776,7 +770,7 @@ test('transferName optionalArguments', async () => { const { namespace, name } = decodeFQN(fullyQualifiedName); const nameTransferPostConditionOne = createNonFungiblePostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), NonFungibleConditionCode.Sends, parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), tupleCV({ @@ -883,7 +877,7 @@ test('renewName', async () => { const { namespace, name } = decodeFQN(fullyQualifiedName); const burnSTXPostCondition = createSTXPostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), FungibleConditionCode.Equal, stxToBurn ); @@ -939,7 +933,7 @@ test('renewName optionalArguments', async () => { const { namespace, name } = decodeFQN(fullyQualifiedName); const burnSTXPostCondition = createSTXPostCondition( - publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), + publicKeyToAddress(getAddressVersion(network), publicKey), FungibleConditionCode.Equal, stxToBurn ); diff --git a/packages/wallet-sdk/tests/models/profile.test.ts b/packages/wallet-sdk/tests/models/profile.test.ts index 57f9a1b6f..944bb600c 100644 --- a/packages/wallet-sdk/tests/models/profile.test.ts +++ b/packages/wallet-sdk/tests/models/profile.test.ts @@ -1,5 +1,5 @@ import { getPublicKeyFromPrivate } from '@stacks/encryption'; -import { makeRandomPrivKey, privateKeyToString } from '@stacks/transactions'; +import { makeRandomPrivKey } from '@stacks/transactions'; import fetchMock from 'jest-fetch-mock'; import { TokenVerifier } from 'jsontokens'; import { @@ -50,7 +50,7 @@ describe(signProfileForUpload, () => { test('sign with unknown private key', () => { const account = mockAccount; - account.stxPrivateKey = privateKeyToString(makeRandomPrivKey()); + account.stxPrivateKey = makeRandomPrivKey(); const profile = DEFAULT_PROFILE; const signedProfileString = signProfileForUpload({ profile, account });