Skip to content

Commit 07a0dbf

Browse files
committed
fix: implement buildNftTransferData for vet
Ticket: COIN-5408
1 parent ed49118 commit 07a0dbf

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

modules/sdk-coin-vet/src/vet.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
BaseCoin,
77
BaseTransaction,
88
BitGoBase,
9+
BuildNftTransferDataOptions,
910
InvalidAddressError,
1011
KeyPair,
1112
MPCAlgorithm,
1213
MultisigType,
1314
multisigTypes,
15+
NotImplementedError,
1416
ParsedTransaction,
1517
SignedTransaction,
1618
SignTransactionOptions,
@@ -238,4 +240,22 @@ export class Vet extends BaseCoin {
238240
},
239241
} as unknown as Hash;
240242
}
243+
244+
buildNftTransferData(params: BuildNftTransferDataOptions): string {
245+
const { recipientAddress, fromAddress } = params;
246+
if (!utils.isValidAddress(recipientAddress)) {
247+
throw new InvalidAddressError('Invalid recipient address');
248+
}
249+
if (!utils.isValidAddress(fromAddress)) {
250+
throw new InvalidAddressError('Invalid from address');
251+
}
252+
switch (params.type) {
253+
case 'ERC721': {
254+
const tokenId = params.tokenId;
255+
return utils.getTransferNFTData(fromAddress, recipientAddress, tokenId);
256+
}
257+
default:
258+
throw new NotImplementedError(`NFT type ${params.type} not supported on ${this.getChain()}`);
259+
}
260+
}
241261
}

modules/sdk-coin-vet/test/resources/vet.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,6 @@ export const SERIALIZED_SIGNED_ADDRESS_INIT_TX =
190190

191191
export const SERIALIZED_SIGNED_FLUSH_TOKEN_TX =
192192
'0xf89827880152cf455536ebc740f83df83b94604a42898388080d56bc85f815965d1f64beb1a680a43ef133670000000000000000000000000000000000000000000000000000456e657267798180830249f08082faf9c0b841b5225a0d5c63fd4ceee2fefe94759d20e37c29ebcd15fc03eb699d4af5bb210c258583f9e8e26e872751e255c2f0fe9d44d52ce65b6b76040476e285074a4b5901';
193+
194+
export const VALID_NFT_CONTRACT_DATA =
195+
'0x23b872dd0000000000000000000000007ca00e3bc8a836026c2917c6c7c6d049e52099dd000000000000000000000000e59f1cea4e0fef511e3d0f4eec44adf19c4cbeec00000000000000000000000000000000000000000000000000000000000004d2';

modules/sdk-coin-vet/test/unit/vet.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sinon from 'sinon';
22
import assert from 'assert';
33
import _ from 'lodash';
4+
import should from 'should';
45
import { BitGoAPI } from '@bitgo/sdk-api';
56
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
67
import { coins, GasTankAccountCoin } from '@bitgo/statics';
@@ -109,6 +110,39 @@ describe('Vechain', function () {
109110
})
110111
.should.rejectedWith('missing required tx prebuild property txHex');
111112
});
113+
114+
it('should build correct nft transfer data', function () {
115+
const data = basecoin.buildNftTransferData({
116+
fromAddress: testData.addresses.validAddresses[0],
117+
recipientAddress: testData.addresses.validAddresses[1],
118+
type: 'ERC721',
119+
tokenId: '1234',
120+
tokenContractAddress: testData.NFT_CONTRACT_ADDRESS,
121+
});
122+
data.should.equal(testData.VALID_NFT_CONTRACT_DATA);
123+
});
124+
125+
it('should build throw invalid address error', function () {
126+
should(() =>
127+
basecoin.buildNftTransferData({
128+
fromAddress: testData.addresses.validAddresses[0],
129+
recipientAddress: testData.addresses.invalidAddresses[0],
130+
type: 'ERC721',
131+
tokenId: '1234',
132+
tokenContractAddress: testData.NFT_CONTRACT_ADDRESS,
133+
})
134+
).throwError('Invalid recipient address');
135+
136+
should(() =>
137+
basecoin.buildNftTransferData({
138+
fromAddress: testData.addresses.invalidAddresses[0],
139+
recipientAddress: testData.addresses.validAddresses[0],
140+
type: 'ERC721',
141+
tokenId: '1234',
142+
tokenContractAddress: testData.NFT_CONTRACT_ADDRESS,
143+
})
144+
).throwError('Invalid from address');
145+
});
112146
});
113147

114148
describe('Parse and Explain Transactions: ', () => {

0 commit comments

Comments
 (0)