Skip to content

Commit

Permalink
test: update bns tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Mar 18, 2024
1 parent 1a37c7e commit 0e63872
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 60 deletions.
52 changes: 24 additions & 28 deletions packages/bns/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
);
Expand Down
54 changes: 24 additions & 30 deletions packages/bns/tests/bns.test.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet-sdk/tests/models/profile.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 0e63872

Please sign in to comment.