CAIP.test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { CHAINS, getLocalChain } = require('../helpers/chains');
  4. describe('CAIP utilities', function () {
  5. before(async function () {
  6. this.local = await getLocalChain();
  7. });
  8. describe('CAIP-2', function () {
  9. before(async function () {
  10. this.mock = await ethers.deployContract('$CAIP2');
  11. });
  12. it('local()', async function () {
  13. const { caip2 } = this.local;
  14. expect(await this.mock.$local()).to.equal(caip2);
  15. });
  16. for (const { namespace, reference, caip2 } of Object.values(CHAINS)) {
  17. it(`format(${namespace}, ${reference})`, async function () {
  18. expect(await this.mock.$format(namespace, reference)).to.equal(caip2);
  19. });
  20. it(`parse(${caip2})`, async function () {
  21. expect(await this.mock.$parse(caip2)).to.deep.equal([namespace, reference]);
  22. });
  23. }
  24. });
  25. describe('CAIP-10', function () {
  26. const { address: account } = ethers.Wallet.createRandom();
  27. before(async function () {
  28. this.mock = await ethers.deployContract('$CAIP10');
  29. });
  30. it(`local(${account})`, async function () {
  31. const caip10 = this.local.toCaip10(account);
  32. expect(await this.mock.$local(ethers.Typed.address(account))).to.equal(caip10);
  33. });
  34. for (const { caip2, toCaip10 } of Object.values(CHAINS)) {
  35. const caip10 = toCaip10(account);
  36. it(`format(${caip2}, ${account})`, async function () {
  37. expect(await this.mock.$format(ethers.Typed.string(caip2), ethers.Typed.string(account))).to.equal(caip10);
  38. });
  39. it(`parse(${caip10})`, async function () {
  40. expect(await this.mock.$parse(caip10)).to.deep.equal([caip2, account]);
  41. });
  42. }
  43. });
  44. });