is_contract.spec.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-License-Identifier: Apache-2.0
  2. import expect from 'expect';
  3. import { createConnection, deploy, aliceKeypair, query, } from './index';
  4. import { ContractPromise } from '@polkadot/api-contract';
  5. import { ApiPromise } from '@polkadot/api';
  6. import { KeyringPair } from '@polkadot/keyring/types';
  7. describe('Deploy the is_contract oracle and test it on contract an non-contract addresses', () => {
  8. let conn: ApiPromise;
  9. let oracle: ContractPromise;
  10. let alice: KeyringPair;
  11. before(async function () {
  12. alice = aliceKeypair();
  13. conn = await createConnection();
  14. const contract = await deploy(conn, alice, 'IsContractOracle.contract', 0n);
  15. oracle = new ContractPromise(conn, contract.abi, contract.address);
  16. });
  17. after(async function () {
  18. await conn.disconnect();
  19. });
  20. it('is correct on a contract address', async function () {
  21. const answer = await query(conn, alice, oracle, "contract_oracle", [oracle.address]);
  22. expect(answer.output?.toJSON()).toStrictEqual(true);
  23. });
  24. it('is correct on a non-contract address', async function () {
  25. const answer = await query(conn, alice, oracle, "contract_oracle", [alice.address]);
  26. expect(answer.output?.toJSON()).toStrictEqual(false);
  27. });
  28. });