Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #88 from rnsdomains/develop
Browse files Browse the repository at this point in the history
v1.7.2
  • Loading branch information
ilanolkies authored May 22, 2020
2 parents 45bb480 + 4cb4e1e commit a1749e4
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsksmart/rns",
"version": "1.7.1",
"version": "1.7.2",
"description": "RIF Name Service library.",
"keywords": [
"rsk",
Expand Down
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export const DEVPORTAL_ERRORS_URL = 'https://developers.rsk.co/rif/rns/libs/java

// contracts interfaces
export const ADDR_INTERFACE = '0x3b3b57de';
export const ERC165_INTERFACE = '0x01ffc9a7';
export const SET_ADDR_INTERFACE = '0xd5fa2b00';
export const CHAIN_ADDR_INTERFACE = '0x8be4b5f6';
export const SET_CHAIN_ADDR_INTERFACE = '0xd278b400';
export const NAME_INTERFACE = '0x691f3431';
export const SET_ADDR_INTERFACE = '0xd8389dc5';
export const AVAILABLE_INTERFACE = '0x96e494e8';
export const SET_NAME_INTERFACE = '0xc47f0027';
export const AVAILABLE_INTERFACE = '0x96e494e8';

export const AVAILABLE_TLDS = ['rsk'];

Expand Down
17 changes: 6 additions & 11 deletions src/resolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createAddrResolver, createChainAddrResolver, createNameResolver, createReverseRegistrar,
} from './factories';
import {
ZERO_ADDRESS, ADDR_INTERFACE, ERC165_INTERFACE,
ZERO_ADDRESS, ADDR_INTERFACE, SET_CHAIN_ADDR_INTERFACE,
CHAIN_ADDR_INTERFACE, NAME_INTERFACE, ADDR_REVERSE_NAMEHASH,
SET_NAME_INTERFACE, SET_ADDR_INTERFACE,
} from './constants';
Expand Down Expand Up @@ -62,16 +62,11 @@ export default class extends Composer implements Resolutions {
throw new RNSError(noResolverError || NO_RESOLVER);
}

const isErc165Contract = await hasMethod(this.blockchainApi, resolverAddress, ERC165_INTERFACE);
if (!isErc165Contract) {
throw new RNSError(errorMessage);
}

const resolver: Contract = contractFactory(this.blockchainApi, resolverAddress);

const supportsInterface: boolean = await resolver.methods.supportsInterface(
methodInterface,
).call();
const supportsInterface: boolean = await hasMethod(
this.blockchainApi, resolverAddress, methodInterface,
);

if (!supportsInterface) {
throw new RNSError(errorMessage);
Expand Down Expand Up @@ -178,7 +173,7 @@ export default class extends Composer implements Resolutions {
/**
* Sets addr for the given domain using the AbstractAddrResolver interface.
*
* @throws NO_ADDR_RESOLUTION it has an invalid resolver - KB002.
* @throws NO_SET_ADDR it has an invalid resolver - KB018.
* @throws NO_RESOLVER when the domain doesn't have resolver - KB003.
* @throws NO_ACCOUNTS_TO_SIGN if the given blockchainApi instance does not have associated accounts to sign the transaction - KB015
* @throws INVALID_ADDRESS if the given addr is invalid - KB017
Expand Down Expand Up @@ -237,7 +232,7 @@ export default class extends Composer implements Resolutions {

const resolver = await this._createResolver(
node,
CHAIN_ADDR_INTERFACE,
SET_CHAIN_ADDR_INTERFACE,
NO_SET_CHAIN_ADDR,
createChainAddrResolver,
);
Expand Down
6 changes: 3 additions & 3 deletions src/subdomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class extends Composer implements Subdomains {
}

/**
* Creates a new subdomain under the given domain tree if not exists.
* Sets a subdomain owner. If the subdomain exists, sets the new owner, if not, creates the subdomain and sets the owner.
*
* @throws SEARCH_DOMAINS_UNDER_AVAILABLE_TLDS if the given domain is not a domain under valid TLDs - KB009
* @throws INVALID_DOMAIN if the given domain is empty, is not alphanumeric or if has uppercase characters - KB010
Expand Down Expand Up @@ -133,8 +133,8 @@ export default class extends Composer implements Subdomains {
}

/**
* Creates a new subdomain under the given domain tree and sets addr if provided
*
* Creates a new subdomain under the given domain tree if it is available, and sets its resolution if addr is provided.
* It could send one, two or three transactions based on the value of the sent parameters.
*
* @throws SEARCH_DOMAINS_UNDER_AVAILABLE_TLDS if the given domain is not a domain under valid TLDs - KB009
* @throws INVALID_DOMAIN if the given domain is empty, is not alphanumeric or if has uppercase characters - KB010
Expand Down
5 changes: 3 additions & 2 deletions src/types/subdomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface Subdomains {
available(domain: string, label: string): Promise<boolean>;

/**
* Creates a new subdomain under the given domain tree
* Sets a subdomain owner. If the subdomain exists, sets the new owner, if not, creates the subdomain and sets the owner.
*
* @param domain - Parent .rsk domain. ie: wallet.rsk
* @param label - Subdomain to register. ie: alice
Expand All @@ -25,7 +25,8 @@ export interface Subdomains {
setOwner(domain: string, label: string, owner: string): Promise<TransactionReceipt>;

/**
* Creates a new subdomain under the given domain tree and sets addr if provided
* Creates a new subdomain under the given domain tree if it is available, and sets its resolution if addr is provided.
* It could send one, two or three transactions based on the value of the sent parameters.
*
* @param domain - Parent .rsk domain. ie: wallet.rsk
* @param label - Subdomain to register. ie: alice
Expand Down
21 changes: 20 additions & 1 deletion test/local/rns.resolve.setAddr.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import RNSRegistryData from '@rsksmart/rns-registry/RNSRegistryData.json';
import AddrResolverData from '@rsksmart/rns-resolver/AddrResolverData.json';
import NameResolverData from '@rsksmart/rns-reverse/NameResolverData.json';
import ChainAddrResolverData from '@rsksmart/rns-resolver/ChainAddrResolverData.json';
import {
contract, web3, defaultSender,
} from '@openzeppelin/test-environment';
Expand Down Expand Up @@ -48,7 +49,25 @@ describe.each([
rns = new RNS(blockchainApiInstance, options);
});

it('should set an address', async () => {
it('should set an address if implements the multichain resolver', async () => {
const MultichainResolver = contract.fromABI(
ChainAddrResolverData.abi, ChainAddrResolverData.bytecode,
);

const multichainResolver = await MultichainResolver.new(
registry.address, publicResolver.address,
);

await registry.setSubnodeOwner(namehash(TLD), labelhash('alice'), defaultSender);
await registry.setResolver(namehash('alice.rsk'), multichainResolver.address);

await rns.setAddr('alice.rsk', addr);

const actualAddr = await rns.addr('alice.rsk');
expect(actualAddr).toBe(addr);
});

it('should set an address with public resolver', async () => {
await registry.setSubnodeOwner(namehash(TLD), labelhash('alice'), defaultSender);

await rns.setAddr('alice.rsk', addr);
Expand Down
12 changes: 6 additions & 6 deletions test/local/rns.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { keccak256 } from 'js-sha3';
import Rsk3 from '@rsksmart/rsk3';
import RNS from '../../src/index';
import { Options, NetworkId } from '../../src/types';
import { ERC165_INTERFACE } from '../../src/constants';
import { ADDR_INTERFACE } from '../../src/constants';

const web3Instance = web3 as unknown as Web3;
const rsk3Instance = new Rsk3(web3.currentProvider);
Expand Down Expand Up @@ -215,25 +215,25 @@ describe.each([
const [anAccount] = accounts;

expect(
await rns.utils.hasMethod(blockchainApiInstance, anAccount, ERC165_INTERFACE),
await rns.utils.hasMethod(blockchainApiInstance, anAccount, ADDR_INTERFACE),
).toEqual(false);
});

it('should return false when sending the registry contract that does not support the ERC165 interface', async () => {
it('should return false when sending the registry contract that does not support the addr interface', async () => {
const hasMethod = await rns.utils.hasMethod(
blockchainApiInstance,
registry.address,
ERC165_INTERFACE,
ADDR_INTERFACE,
);
expect(hasMethod).toEqual(false);
});

it('should return true when sending the publicResolver contract that supports the ERC165 interface', async () => {
it('should return true when sending the publicResolver contract that supports the addr interface', async () => {
const PublicResolver = contract.fromABI(AddrResolverData.abi, AddrResolverData.bytecode);
const publicResolver = await PublicResolver.new(registry.address);

const hasMethod = await rns.utils.hasMethod(
blockchainApiInstance, publicResolver.address, ERC165_INTERFACE,
blockchainApiInstance, publicResolver.address, ADDR_INTERFACE,
);
expect(hasMethod).toEqual(true);
});
Expand Down

0 comments on commit a1749e4

Please sign in to comment.