Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update connector to support custom URI's #61

Merged
merged 6 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@nestjs/websockets": "^8.0.11",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"lru-cache": "^7.10.1",
"nanoid": "^3.1.31",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.4.0",
Expand All @@ -44,6 +45,7 @@
"@nestjs/testing": "^8.0.11",
"@types/express": "^4.17.8",
"@types/jest": "^26.0.15",
"@types/lru-cache": "^7.10.10",
"@types/node": "^14.14.6",
"@types/supertest": "^2.0.10",
"@types/uuid": "^8.3.1",
Expand Down
4 changes: 4 additions & 0 deletions samples/solidity/contracts/ERC721WithData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ contract ERC721WithData is Context, Ownable, ERC721, IERC721WithData {
require(_exists(tokenId), "ERC721WithData: Token does not exist");
_tokenURIs[tokenId] = _tokenURI;
}

function baseTokenUri() public view virtual override returns (string memory) {
return _baseURI();
}
}
2 changes: 2 additions & 0 deletions samples/solidity/contracts/IERC721WithData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ interface IERC721WithData is IERC165 {
bool approved,
bytes calldata data
) external;

function baseTokenUri() external returns(string memory);
}
3 changes: 2 additions & 1 deletion samples/solidity/test/ERC721WithData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ describe('ERC721WithData - Unit Tests', function () {
it('Verify interface ID', async function () {
const checkerFactory = await ethers.getContractFactory('InterfaceCheck');
const checker: InterfaceCheck = await checkerFactory.connect(deployerSignerA).deploy();
expect(await checker.erc721WithData()).to.equal('0xfd0771df');
expect(await checker.erc721WithData()).to.equal('0x8706707d');
});

it('Create - Should create a new ERC721 instance with default state', async function () {
expect(await deployedERC721WithData.name()).to.equal(contractName);
expect(await deployedERC721WithData.symbol()).to.equal(contractSymbol);
expect(await deployedERC721WithData.baseTokenUri()).to.equal("firefly://token/");
});

it('Mint - Should mint successfully with a custom URI', async function () {
Expand Down
50 changes: 48 additions & 2 deletions src/abi/ERC721WithData.json

Large diffs are not rendered by default.

28 changes: 26 additions & 2 deletions src/abi/TokenFactory.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/tokens/tokens.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export class TokenPoolConfig {
@ApiProperty()
@IsOptional()
blockNumber?: string;

@ApiProperty()
@IsOptional()
uri?: string;
}

export class TokenPool {
Expand Down Expand Up @@ -300,7 +304,11 @@ export class TokenTransfer {
data?: string;
}

export class TokenMint extends OmitType(TokenTransfer, ['from']) {}
export class TokenMint extends OmitType(TokenTransfer, ['from']) {
@ApiProperty()
@IsOptional()
uri?: string;
}
export class TokenBurn extends OmitType(TokenTransfer, ['to']) {}

// Websocket notifications
Expand Down Expand Up @@ -332,6 +340,10 @@ export class TokenPoolEventInfo {

@ApiProperty()
schema: string;

@ApiProperty()
@IsOptional()
uri?: string;
}

export class TokenPoolEvent extends tokenEventBase {
Expand Down
74 changes: 73 additions & 1 deletion src/tokens/tokens.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,24 @@ const APPROVE_NO_DATA = 'approve';
const APPROVE_ALL_NO_DATA = 'setApprovalForAll';

const MINT_WITH_DATA = 'mintWithData';
const MINT_WITH_URI = 'mintWithURI';
const SUPPORTS_INTERFACE = 'supportsInterface';
const TRANSFER_WITH_DATA = 'transferWithData';
const BURN_WITH_DATA = 'burnWithData';
const APPROVE_WITH_DATA = 'approveWithData';
const APPROVE_ALL_WITH_DATA = 'setApprovalForAllWithData';
const BASE_URI = 'baseTokenUri';

const METHODS_NO_DATA = [MINT_NO_DATA, BURN_NO_DATA, APPROVE_NO_DATA, APPROVE_ALL_NO_DATA];

const METHODS_WITH_DATA = [
MINT_WITH_DATA,
MINT_WITH_URI,
BURN_WITH_DATA,
TRANSFER_WITH_DATA,
APPROVE_WITH_DATA,
APPROVE_ALL_WITH_DATA,
BASE_URI,
];

const TRANSFER_EVENT = 'Transfer';
Expand Down Expand Up @@ -159,6 +164,19 @@ describe('TokensService', () => {
}),
);
}
http.post.mockReturnValueOnce(
new FakeObservable(<EthConnectReturn>{
output: 'test',
}),
);
};

const mockURIQuery = (withURI: boolean) => {
http.post.mockReturnValueOnce(
new FakeObservable(<EthConnectReturn>{
output: withURI,
}),
);
};

beforeEach(async () => {
Expand Down Expand Up @@ -212,6 +230,7 @@ describe('TokensService', () => {
symbol: SYMBOL,
};

mockURIQuery(false);
mockPoolQuery(false, true);

await service.createPool(request).then(resp => {
Expand Down Expand Up @@ -384,6 +403,7 @@ describe('TokensService', () => {
symbol: SYMBOL,
};

mockURIQuery(false);
mockPoolQuery(true, true);

await service.createPool(request).then(resp => {
Expand Down Expand Up @@ -414,6 +434,7 @@ describe('TokensService', () => {
symbol: SYMBOL,
};

mockURIQuery(false);
mockPoolQuery(true, true);

await service.createPool(request).then(resp => {
Expand Down Expand Up @@ -582,6 +603,7 @@ describe('TokensService', () => {
symbol: SYMBOL,
};

mockURIQuery(false);
mockPoolQuery(false, false);

await service.createPool(request).then(resp => {
Expand Down Expand Up @@ -767,7 +789,8 @@ describe('TokensService', () => {
symbol: SYMBOL,
};

mockPoolQuery(true, false);
mockURIQuery(true);
mockPoolQuery(undefined, false);

await service.createPool(request).then(resp => {
expect(resp).toEqual({
Expand All @@ -781,6 +804,7 @@ describe('TokensService', () => {
name: NAME,
address: CONTRACT_ADDRESS,
schema: ERC721_WITH_DATA_SCHEMA,
uri: 'test',
},
} as TokenPoolEvent);
});
Expand All @@ -797,6 +821,7 @@ describe('TokensService', () => {
symbol: SYMBOL,
};

mockURIQuery(false);
mockPoolQuery(true, false);

await service.createPool(request).then(resp => {
Expand Down Expand Up @@ -840,6 +865,7 @@ describe('TokensService', () => {
},
};

// mockURIQuery(false);
mockPoolQuery(undefined, false);

eventstream.createOrUpdateStream = jest.fn(() => mockEventStream);
Expand Down Expand Up @@ -904,6 +930,52 @@ describe('TokensService', () => {
expect(http.post).toHaveBeenCalledWith(BASE_URL, mockEthConnectRequest, OPTIONS);
});

it('should mint ERC721WithData token with correct abi, custom uri, and inputs', async () => {
const request: TokenMint = {
tokenIndex: '721',
signer: IDENTITY,
poolLocator: ERC721_WITH_DATA_POOL_ID,
to: '0x123',
uri: 'ipfs://CID',
};

const mockEthConnectURIQuery: EthConnectMsgRequest = {
headers: {
type: 'Query',
},
to: CONTRACT_ADDRESS,
method: abiTypeMap.ERC721WithData.find(
abi => abi.name === SUPPORTS_INTERFACE,
) as IAbiMethod,
params: ['0x8706707d'],
};

const mockEthConnectRequest: EthConnectMsgRequest = {
headers: {
type: 'SendTransaction',
},
from: IDENTITY,
to: CONTRACT_ADDRESS,
method: abiTypeMap.ERC721WithData.find(abi => abi.name === MINT_WITH_URI) as IAbiMethod,
params: ['0x123', '721', '0x00', 'ipfs://CID'],
};

const response: EthConnectAsyncResponse = {
id: 'responseId',
sent: true,
};

mockURIQuery(true);

http.post.mockReturnValueOnce(new FakeObservable(response));
await expect(service.mint(request)).resolves.toEqual({
id: 'responseId',
} as AsyncResponse);

expect(http.post).toHaveBeenCalledWith(BASE_URL, mockEthConnectURIQuery, OPTIONS);
expect(http.post).toHaveBeenCalledWith(BASE_URL, mockEthConnectRequest, OPTIONS);
});

it('should transfer ERC721WithData token with correct abi and inputs', async () => {
const request: TokenTransfer = {
tokenIndex: '721',
Expand Down
Loading