|  | 
|  | 1 | +import chai, { expect } from 'chai' | 
|  | 2 | +import chaiAsPromised from 'chai-as-promised' | 
|  | 3 | +import { ethers } from 'ethers' | 
|  | 4 | +import { GraphRuntimeEnvironment } from '../type-extensions' | 
|  | 5 | +import { useEnvironment } from './helpers' | 
|  | 6 | + | 
|  | 7 | +chai.use(chaiAsPromised) | 
|  | 8 | + | 
|  | 9 | +const mnemonic = 'pumpkin orient can short never warm truth legend cereal tourist craft skin' | 
|  | 10 | + | 
|  | 11 | +describe('GRE usage > account management', function () { | 
|  | 12 | +  // Tests that loop through all the wallets take more than the default timeout | 
|  | 13 | +  this.timeout(10_000) | 
|  | 14 | + | 
|  | 15 | +  useEnvironment('graph-config', 'hardhat') | 
|  | 16 | + | 
|  | 17 | +  let graph: GraphRuntimeEnvironment | 
|  | 18 | + | 
|  | 19 | +  beforeEach(function () { | 
|  | 20 | +    graph = this.hre.graph() | 
|  | 21 | +  }) | 
|  | 22 | + | 
|  | 23 | +  describe('getWallets', function () { | 
|  | 24 | +    it('should return 20 wallets', async function () { | 
|  | 25 | +      const wallets = await graph.getWallets() | 
|  | 26 | +      expect(wallets.length).to.equal(20) | 
|  | 27 | +    }) | 
|  | 28 | + | 
|  | 29 | +    it('should derive wallets from hardhat config mnemonic', async function () { | 
|  | 30 | +      const wallets = await graph.getWallets() | 
|  | 31 | + | 
|  | 32 | +      for (let i = 0; i < wallets.length; i++) { | 
|  | 33 | +        const derived = ethers.Wallet.fromMnemonic(mnemonic, `m/44'/60'/0'/0/${i}`) | 
|  | 34 | +        expect(wallets[i].address).to.equal(derived.address) | 
|  | 35 | +      } | 
|  | 36 | +    }) | 
|  | 37 | + | 
|  | 38 | +    it('should return wallets capable of signing messages', async function () { | 
|  | 39 | +      const wallets = await graph.getWallets() | 
|  | 40 | + | 
|  | 41 | +      for (const wallet of wallets) { | 
|  | 42 | +        expect(wallet.signMessage('test')).to.eventually.be.fulfilled | 
|  | 43 | +      } | 
|  | 44 | +    }) | 
|  | 45 | + | 
|  | 46 | +    it('should return wallets not connected to a provider', async function () { | 
|  | 47 | +      const wallets = await graph.getWallets() | 
|  | 48 | + | 
|  | 49 | +      for (const wallet of wallets) { | 
|  | 50 | +        expect(wallet.provider).to.be.null | 
|  | 51 | +      } | 
|  | 52 | +    }) | 
|  | 53 | +  }) | 
|  | 54 | + | 
|  | 55 | +  describe('getWallet', function () { | 
|  | 56 | +    it('should return wallet if provided address can be derived from mnemonic', async function () { | 
|  | 57 | +      for (let i = 0; i < 20; i++) { | 
|  | 58 | +        const derived = ethers.Wallet.fromMnemonic(mnemonic, `m/44'/60'/0'/0/${i}`) | 
|  | 59 | +        const wallet = await graph.getWallet(derived.address) | 
|  | 60 | +        expect(wallet.address).to.equal(derived.address) | 
|  | 61 | +      } | 
|  | 62 | +    }) | 
|  | 63 | + | 
|  | 64 | +    it('should return wallet capable of signing messages', async function () { | 
|  | 65 | +      for (let i = 0; i < 20; i++) { | 
|  | 66 | +        const derived = ethers.Wallet.fromMnemonic(mnemonic, `m/44'/60'/0'/0/${i}`) | 
|  | 67 | +        const wallet = await graph.getWallet(derived.address) | 
|  | 68 | +        expect(wallet.signMessage('test')).to.eventually.be.fulfilled | 
|  | 69 | +      } | 
|  | 70 | +    }) | 
|  | 71 | + | 
|  | 72 | +    it('should return wallet not connected to a provider', async function () { | 
|  | 73 | +      for (let i = 0; i < 20; i++) { | 
|  | 74 | +        const derived = ethers.Wallet.fromMnemonic(mnemonic, `m/44'/60'/0'/0/${i}`) | 
|  | 75 | +        const wallet = await graph.getWallet(derived.address) | 
|  | 76 | +        expect(wallet.provider).to.be.null | 
|  | 77 | +      } | 
|  | 78 | +    }) | 
|  | 79 | + | 
|  | 80 | +    it('should return undefined if provided address cant be derived from mnemonic', async function () { | 
|  | 81 | +      const wallet = await graph.getWallet('0x0000000000000000000000000000000000000000') | 
|  | 82 | +      expect(wallet).to.be.undefined | 
|  | 83 | +    }) | 
|  | 84 | +  }) | 
|  | 85 | +}) | 
0 commit comments