-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from starknet-id/feat/add_ccip
feat: update getAddressFromStarkName to work with ccip
- Loading branch information
Showing
8 changed files
with
10,283 additions
and
18 deletions.
There are no files selected for viewing
6,883 changes: 6,883 additions & 0 deletions
6,883
packages/core/__mocks__/resolver/resolver.compiled_contract_class.json
Large diffs are not rendered by default.
Oops, something went wrong.
3,057 changes: 3,057 additions & 0 deletions
3,057
packages/core/__mocks__/resolver/resolver.contract_class.json
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
import { Account, constants } from "starknet"; | ||
import { StarknetIdNavigator } from "../src"; | ||
import { | ||
compiledIdentitySierra, | ||
compiledIdentitySierraCasm, | ||
compiledNamingSierra, | ||
compiledNamingSierraCasm, | ||
compiledPricingSierra, | ||
compiledPricingSierraCasm, | ||
compiledResolverSierra, | ||
compiledResolverSierraCasm, | ||
getTestAccount, | ||
getTestProvider, | ||
} from "./fixtures"; | ||
|
||
global.fetch = jest.fn(); | ||
|
||
describe("test starknetid.js sdk", () => { | ||
jest.setTimeout(90000000); | ||
const provider = getTestProvider(); | ||
const account = getTestAccount(provider)[0]; | ||
|
||
let erc20Address: string = | ||
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"; | ||
let NamingContract: string; | ||
let IdentityContract: string; | ||
let ResolverContract: string; | ||
|
||
beforeAll(async () => { | ||
expect(account).toBeInstanceOf(Account); | ||
|
||
// Deploy Identity contract | ||
const idResponse = await account.declareAndDeploy( | ||
{ | ||
contract: compiledIdentitySierra, | ||
casm: compiledIdentitySierraCasm, | ||
constructorCalldata: [account.address, 0], | ||
}, | ||
{ maxFee: 1e18 }, | ||
); | ||
IdentityContract = idResponse.deploy.contract_address; | ||
|
||
// Deploy pricing contract | ||
const pricingResponse = await account.declareAndDeploy( | ||
{ | ||
contract: compiledPricingSierra, | ||
casm: compiledPricingSierraCasm, | ||
constructorCalldata: [erc20Address], | ||
}, | ||
{ maxFee: 1e18 }, | ||
); | ||
const pricingContractAddress = pricingResponse.deploy.contract_address; | ||
|
||
// Deploy naming contract | ||
const namingResponse = await account.declareAndDeploy( | ||
{ | ||
contract: compiledNamingSierra, | ||
casm: compiledNamingSierraCasm, | ||
constructorCalldata: [ | ||
IdentityContract, | ||
pricingContractAddress, | ||
0, | ||
account.address, | ||
], | ||
}, | ||
{ maxFee: 1e18 }, | ||
); | ||
NamingContract = namingResponse.deploy.contract_address; | ||
|
||
// Deploy resolver contract | ||
const publicKey = | ||
"0x1ef1ffcd39066b79fd741ed17c8bed5fab0160591d8b7177211f5e7f5517a04"; | ||
const serverUri = ["http://0.0.0.0:8090/resolve?do", "main="]; | ||
const resolverResponse = await account.declareAndDeploy( | ||
{ | ||
contract: compiledResolverSierra, | ||
casm: compiledResolverSierraCasm, | ||
constructorCalldata: [account.address, publicKey], | ||
}, | ||
{ maxFee: 1e18 }, | ||
); | ||
ResolverContract = resolverResponse.deploy.contract_address; | ||
|
||
const { transaction_hash } = await account.execute( | ||
[ | ||
{ | ||
contractAddress: erc20Address, | ||
entrypoint: "approve", | ||
calldata: [NamingContract, 0, 1], // Price of domain | ||
}, | ||
{ | ||
contractAddress: IdentityContract, | ||
entrypoint: "mint", | ||
calldata: ["1"], // TokenId | ||
}, | ||
{ | ||
contractAddress: NamingContract, | ||
entrypoint: "buy", | ||
calldata: [ | ||
"1", // Starknet id linked | ||
"1068731", // Domain encoded "test" | ||
"365", // days | ||
ResolverContract, // resolver | ||
0, // sponsor | ||
0, | ||
0, | ||
], | ||
}, | ||
{ | ||
contractAddress: IdentityContract, | ||
entrypoint: "set_main_id", | ||
calldata: ["1"], | ||
}, | ||
{ | ||
contractAddress: ResolverContract, | ||
entrypoint: "add_uri", | ||
calldata: [2, ...serverUri], | ||
}, | ||
], | ||
undefined, | ||
{ maxFee: 1e18 }, | ||
); | ||
await provider.waitForTransaction(transaction_hash); | ||
}); | ||
|
||
describe("resolve domain", () => { | ||
beforeEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
|
||
test("resolve subdomain returns the right address", async () => { | ||
fetch.mockResolvedValue({ | ||
ok: true, | ||
json: async () => ({ | ||
address: | ||
"0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691", | ||
r: "0x7bdc9f102e7085464431ae1a89f1d1cc51abf0a1dfa3fba8016b05cb4365219", | ||
s: "0x6d557890203c75df13d880691ac8af5323d0cb7c944d34fc271425f442eae9f", | ||
max_validity: 1716966719, | ||
}), | ||
}); | ||
const starknetIdNavigator = new StarknetIdNavigator( | ||
provider, | ||
constants.StarknetChainId.SN_GOERLI, | ||
{ | ||
naming: NamingContract, | ||
identity: IdentityContract, | ||
}, | ||
); | ||
expect(starknetIdNavigator).toBeInstanceOf(StarknetIdNavigator); | ||
const address = await starknetIdNavigator.getAddressFromStarkName( | ||
"iris.test.stark", | ||
); | ||
expect(address).toBe(account.address); | ||
}); | ||
|
||
test("resolve root domain returns the right address", async () => { | ||
const starknetIdNavigator = new StarknetIdNavigator( | ||
provider, | ||
constants.StarknetChainId.SN_GOERLI, | ||
{ | ||
naming: NamingContract, | ||
identity: IdentityContract, | ||
}, | ||
); | ||
expect(starknetIdNavigator).toBeInstanceOf(StarknetIdNavigator); | ||
const address = await starknetIdNavigator.getAddressFromStarkName( | ||
"test.stark", | ||
); | ||
expect(address).toBe(account.address); | ||
}); | ||
|
||
test("resolve subdomain that is not registered returns an error", async () => { | ||
fetch.mockResolvedValue({ | ||
ok: false, | ||
json: async () => ({ error: "Domain not found" }), | ||
}); | ||
const starknetIdNavigator = new StarknetIdNavigator( | ||
provider, | ||
constants.StarknetChainId.SN_GOERLI, | ||
{ | ||
naming: NamingContract, | ||
identity: IdentityContract, | ||
}, | ||
); | ||
expect(starknetIdNavigator).toBeInstanceOf(StarknetIdNavigator); | ||
await expect( | ||
starknetIdNavigator.getAddressFromStarkName("notworking.test.stark"), | ||
).rejects.toThrow("Could not get address from stark name"); | ||
}); | ||
}); | ||
}); |
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.