forked from starknet-io/starknet.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update starknetId class and add getStarkProfile function
- Loading branch information
Showing
16 changed files
with
73,957 additions
and
98,068 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
11,765 changes: 11,765 additions & 0 deletions
11,765
__mocks__/starknetId/identity/identity.sierra.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
1,602 changes: 1,602 additions & 0 deletions
1,602
__mocks__/starknetId/multicall/multicall.sierra.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
10,020 changes: 10,020 additions & 0 deletions
10,020
__mocks__/starknetId/naming/naming.sierra.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.