Skip to content

Commit

Permalink
feat: update starknetId class and add getStarkProfile function
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv authored Mar 11, 2024
1 parent fb4bd58 commit ae71c97
Show file tree
Hide file tree
Showing 16 changed files with 73,957 additions and 98,068 deletions.
53,283 changes: 0 additions & 53,283 deletions __mocks__/naming_compiled.json

This file was deleted.

23,476 changes: 23,476 additions & 0 deletions __mocks__/starknetId/identity/identity.casm

Large diffs are not rendered by default.

11,765 changes: 11,765 additions & 0 deletions __mocks__/starknetId/identity/identity.sierra.json

Large diffs are not rendered by default.

3,407 changes: 3,407 additions & 0 deletions __mocks__/starknetId/multicall/multicall.casm

Large diffs are not rendered by default.

1,602 changes: 1,602 additions & 0 deletions __mocks__/starknetId/multicall/multicall.sierra.json

Large diffs are not rendered by default.

20,643 changes: 20,643 additions & 0 deletions __mocks__/starknetId/naming/naming.casm

Large diffs are not rendered by default.

10,020 changes: 10,020 additions & 0 deletions __mocks__/starknetId/naming/naming.sierra.json

Large diffs are not rendered by default.

1,660 changes: 1,660 additions & 0 deletions __mocks__/starknetId/pricing/pricing.casm

Large diffs are not rendered by default.

836 changes: 836 additions & 0 deletions __mocks__/starknetId/pricing/pricing.sierra.json

Large diffs are not rendered by default.

44,703 changes: 0 additions & 44,703 deletions __mocks__/starknetId_compiled.json

This file was deleted.

160 changes: 160 additions & 0 deletions __tests__/account.starknetId.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { Provider, num, shortString } from '../src';
import {
compiledNaming,
compiledNamingCasm,
compiledPricing,
compiledPricingCasm,
compiledSidMulticall,
compiledSidMulticallCasm,
compiledStarknetId,
compiledStarknetIdCasm,
getTestAccount,
getTestProvider,
} from './config/fixtures';

const { hexToDecimalString } = num;

describe('deploy and test Wallet', () => {
const provider = new Provider(getTestProvider());
const account = getTestAccount(provider);
let identityAddress: string;
let namingAddress: string;
let multicallAddress: string;
const devnetERC20Address = '0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7';

beforeAll(async () => {
// Deploy Starknet id contract
const idResponse = await account.declareAndDeploy(
{
contract: compiledStarknetId,
casm: compiledStarknetIdCasm,
constructorCalldata: [account.address, 0],
},
{ maxFee: 1e18 }
);
identityAddress = idResponse.deploy.contract_address;

// Deploy pricing contract
const pricingResponse = await account.declareAndDeploy(
{
contract: compiledPricing,
casm: compiledPricingCasm,
constructorCalldata: [devnetERC20Address],
},
{ maxFee: 1e18 }
);
const pricingAddress = pricingResponse.deploy.contract_address;

// Deploy naming contract
const namingResponse = await account.declareAndDeploy(
{
contract: compiledNaming,
casm: compiledNamingCasm,
constructorCalldata: [identityAddress, pricingAddress, 0, account.address],
},
{ maxFee: 1e18 }
);
namingAddress = namingResponse.deploy.contract_address;

// Deploy multicall contract
const multicallResponse = await account.declareAndDeploy(
{
contract: compiledSidMulticall,
casm: compiledSidMulticallCasm,
},
{ maxFee: 1e18 }
);
multicallAddress = multicallResponse.deploy.contract_address;

const { transaction_hash } = await account.execute(
[
{
contractAddress: devnetERC20Address,
entrypoint: 'approve',
calldata: [namingAddress, 0, 1], // Price of domain
},
{
contractAddress: identityAddress,
entrypoint: 'mint',
calldata: ['1'], // TokenId
},
{
contractAddress: namingAddress,
entrypoint: 'buy',
calldata: [
'1', // Starknet id linked
'1499554868251', // Domain encoded "fricoben"
'62', // days
'0', // resolver
0, // sponsor
0,
0,
],
},
{
contractAddress: identityAddress,
entrypoint: 'set_main_id',
calldata: ['1'],
},
],
undefined,
{ maxFee: 1e18 }
);

await provider.waitForTransaction(transaction_hash);
});

test('Get the stark name of the account (using starknet.id)', async () => {
const address = await account.getAddressFromStarkName('fricoben.stark', namingAddress);
expect(hexToDecimalString(address as string)).toEqual(hexToDecimalString(account.address));
});

test('Get the account from a stark name of the account (using starknet.id)', async () => {
const name = await account.getStarkName(undefined, namingAddress);
expect(name).toEqual('fricoben.stark');
});

describe('Test getStarkProfile', () => {
beforeAll(async () => {
// Add verifier data
const { transaction_hash: transaction_hash_verifier } = await account.execute(
[
{
contractAddress: identityAddress,
entrypoint: 'set_verifier_data',
calldata: [
'1', // token_id
shortString.encodeShortString('discord'), // field
123, // value
0,
],
},
],
undefined,
{ maxFee: 1e18 }
);
await provider.waitForTransaction(transaction_hash_verifier);
});

test('Get the profile data from an address (using starknet.id)', async () => {
const profile = await account.getStarkProfile(
account.address,
namingAddress,
identityAddress,
account.address,
account.address,
account.address,
multicallAddress
);
const expectedProfile = {
name: 'fricoben.stark',
twitter: undefined,
github: undefined,
discord: '123',
proofOfPersonhood: false,
profilePicture: 'https://starknet.id/api/identicons/1',
};
expect(profile).toStrictEqual(expectedProfile);
});
});
});
74 changes: 0 additions & 74 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import {
compiledErc20,
compiledHelloSierra,
compiledHelloSierraCasm,
compiledNamingContract,
compiledOpenZeppelinAccount,
compiledStarknetId,
compiledTestDapp,
describeIfDevnet,
describeIfDevnetSequencer,
Expand Down Expand Up @@ -457,78 +455,6 @@ describe('deploy and test Wallet', () => {
}
expect(declareTx).toMatchSchemaRef('DeclareContractResponse');
});

test('Get the stark name of the account and account from stark name (using starknet.id)', async () => {
// Deploy naming contract
const namingResponse = await account.declareAndDeploy({
contract: compiledNamingContract,
});
const namingAddress = namingResponse.deploy.contract_address;

// Deploy Starknet id contract
const idResponse = await account.declareAndDeploy({
contract: compiledStarknetId,
});
const idAddress = idResponse.deploy.contract_address;

// Create signature from private key
const whitelistingPublicKey =
'1893860513534673656759973582609638731665558071107553163765293299136715951024';
const whitelistingPrivateKey =
'301579081698031303837612923223391524790804435085778862878979120159194507372';
const hashed = ec.starkCurve.pedersen(
ec.starkCurve.pedersen(toBigInt('18925'), toBigInt('1922775124')),
toBigInt(account.address)
);
const signed = ec.starkCurve.sign(hashed, toHex(whitelistingPrivateKey));

const { transaction_hash } = await account.execute([
{
contractAddress: namingAddress,
entrypoint: 'initializer',
calldata: [
idAddress, // starknetid_contract_addr
'0', // pricing_contract_addr
account.address, // admin
whitelistingPublicKey, // whitelisting_key
'0', // l1_contract
],
},
{
contractAddress: idAddress,
entrypoint: 'mint',
calldata: ['1'], // TokenId
},
{
contractAddress: namingAddress,
entrypoint: 'whitelisted_mint',
calldata: [
'18925', // Domain encoded "ben"
'1922775124', // Expiry
'1', // Starknet id linked
account.address, // receiver_address
signed.r, // sig 0 for whitelist
signed.s, // sig 1 for whitelist
],
},
{
contractAddress: namingAddress,
entrypoint: 'set_address_to_domain',
calldata: [
'1', // length
'18925', // Domain encoded "ben"
],
},
]);

await provider.waitForTransaction(transaction_hash);

const address = await account.getAddressFromStarkName('ben.stark', namingAddress);
expect(hexToDecimalString(address as string)).toEqual(hexToDecimalString(account.address));

const name = await account.getStarkName(undefined, namingAddress);
expect(name).toEqual('ben.stark');
});
});

describe('Declare and UDC Deploy Flow', () => {
Expand Down
11 changes: 9 additions & 2 deletions __tests__/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export const compiledL1L2 = readContract('l1l2_compiled');
export const compiledTypeTransformation = readContract('contract');
export const compiledMulticall = readContract('multicall');
export const compiledTestDapp = readContract('TestDapp');
export const compiledStarknetId = readContract('starknetId_compiled');
export const compiledNamingContract = readContract('naming_compiled');
export const compiledHashSierra = readContractSierra('cairo/hash/hash');
export const compiledHashSierraCasm = readContractSierraCasm('cairo/hash/hash');
export const compiledHelloSierra = readContractSierra('cairo/helloSierra/hello');
Expand All @@ -50,6 +48,15 @@ export const compiledC240 = readContractSierra('cairo/cairo240/string.sierra');
export const compiledC240Casm = readContractSierraCasm('cairo/cairo240/string');
export const compiledTuple = readContractSierra('cairo/cairo253/tupleResponse.sierra');
export const compiledTupleCasm = readContractSierraCasm('cairo/cairo253/tupleResponse');
// StarknetId
export const compiledStarknetId = readContractSierra('starknetId/identity/identity.sierra');
export const compiledStarknetIdCasm = readContractSierraCasm('starknetId/identity/identity');
export const compiledNaming = readContractSierra('starknetId/naming/naming.sierra');
export const compiledNamingCasm = readContractSierraCasm('starknetId/naming/naming');
export const compiledPricing = readContractSierra('starknetId/pricing/pricing.sierra');
export const compiledPricingCasm = readContractSierraCasm('starknetId/pricing/pricing');
export const compiledSidMulticall = readContractSierra('starknetId/multicall/multicall.sierra');
export const compiledSidMulticallCasm = readContractSierraCasm('starknetId/multicall/multicall');

export function getTestProvider(isProvider?: true): ProviderInterface;
export function getTestProvider(isProvider?: false): RpcProvider;
Expand Down
Loading

0 comments on commit ae71c97

Please sign in to comment.