@@ -2,8 +2,9 @@ import { Tempo } from '../../src/tempo';
22import { Ttempo } from '../../src/ttempo' ;
33import { BitGoAPI } from '@bitgo/sdk-api' ;
44import { TestBitGo , TestBitGoAPI } from '@bitgo/sdk-test' ;
5- import { BitGoBase } from '@bitgo/sdk-core' ;
5+ import { BitGoBase , InvalidAddressError , InvalidMemoIdError } from '@bitgo/sdk-core' ;
66import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics' ;
7+ import * as should from 'should' ;
78
89describe ( 'Tempo Coin' , function ( ) {
910 let bitgo : TestBitGoAPI ;
@@ -42,6 +43,110 @@ describe('Tempo Coin', function () {
4243 basecoin . getBaseFactor ( ) . should . equal ( 1e18 ) ;
4344 } ) ;
4445
46+ describe ( 'Address Validation' , function ( ) {
47+ it ( 'should validate plain EVM address' , function ( ) {
48+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f' ) . should . equal ( true ) ;
49+ basecoin . isValidAddress ( '0x0000000000000000000000000000000000000000' ) . should . equal ( true ) ;
50+ } ) ;
51+
52+ it ( 'should validate address with memoId' , function ( ) {
53+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=8' ) . should . equal ( true ) ;
54+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=0' ) . should . equal ( true ) ;
55+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=12345' ) . should . equal ( true ) ;
56+ } ) ;
57+
58+ it ( 'should reject invalid addresses' , function ( ) {
59+ basecoin . isValidAddress ( 'invalid' ) . should . equal ( false ) ;
60+ basecoin . isValidAddress ( '' ) . should . equal ( false ) ;
61+ basecoin . isValidAddress ( '0x123' ) . should . equal ( false ) ; // Too short
62+ } ) ;
63+
64+ it ( 'should reject address with invalid memoId' , function ( ) {
65+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=abc' ) . should . equal ( false ) ;
66+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=-1' ) . should . equal ( false ) ;
67+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=1.5' ) . should . equal ( false ) ;
68+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=01' ) . should . equal ( false ) ; // Leading zero
69+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=' ) . should . equal ( false ) ; // Empty memoId
70+ } ) ;
71+
72+ it ( 'should reject address with unknown query parameters' , function ( ) {
73+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?invalid=123' ) . should . equal ( false ) ;
74+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?foo=bar' ) . should . equal ( false ) ;
75+ } ) ;
76+
77+ it ( 'should reject address with multiple memoId parameters' , function ( ) {
78+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=1&memoId=2' ) . should . equal ( false ) ;
79+ } ) ;
80+
81+ it ( 'should reject address with extra query parameters besides memoId' , function ( ) {
82+ basecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=1&foo=bar' ) . should . equal ( false ) ;
83+ } ) ;
84+ } ) ;
85+
86+ describe ( 'getAddressDetails' , function ( ) {
87+ it ( 'should get address details without memoId' , function ( ) {
88+ const addressDetails = basecoin . getAddressDetails ( '0x2476602c78e9a5e0563320c78878faa3952b256f' ) ;
89+ addressDetails . address . should . equal ( '0x2476602c78e9a5e0563320c78878faa3952b256f' ) ;
90+ addressDetails . baseAddress . should . equal ( '0x2476602c78e9a5e0563320c78878faa3952b256f' ) ;
91+ should . not . exist ( addressDetails . memoId ) ;
92+ } ) ;
93+
94+ it ( 'should get address details with memoId' , function ( ) {
95+ const addressDetails = basecoin . getAddressDetails ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=8' ) ;
96+ addressDetails . address . should . equal ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=8' ) ;
97+ addressDetails . baseAddress . should . equal ( '0x2476602c78e9a5e0563320c78878faa3952b256f' ) ;
98+ addressDetails . memoId . should . equal ( '8' ) ;
99+ } ) ;
100+
101+ it ( 'should throw on invalid memoId address' , function ( ) {
102+ ( ( ) => basecoin . getAddressDetails ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=abc' ) ) . should . throw (
103+ InvalidMemoIdError
104+ ) ;
105+ } ) ;
106+
107+ it ( 'should throw on multiple memoId address' , function ( ) {
108+ ( ( ) => basecoin . getAddressDetails ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=1&memoId=2' ) ) . should . throw (
109+ InvalidAddressError
110+ ) ;
111+ } ) ;
112+
113+ it ( 'should throw on unknown query parameters' , function ( ) {
114+ ( ( ) => basecoin . getAddressDetails ( '0x2476602c78e9a5e0563320c78878faa3952b256f?invalid=8' ) ) . should . throw (
115+ InvalidAddressError
116+ ) ;
117+ } ) ;
118+
119+ it ( 'should throw on empty memoId' , function ( ) {
120+ ( ( ) => basecoin . getAddressDetails ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=' ) ) . should . throw (
121+ InvalidAddressError
122+ ) ;
123+ } ) ;
124+
125+ it ( 'should throw on extra query parameters besides memoId' , function ( ) {
126+ ( ( ) => basecoin . getAddressDetails ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=1&foo=bar' ) ) . should . throw (
127+ InvalidAddressError
128+ ) ;
129+ } ) ;
130+ } ) ;
131+
132+ describe ( 'isValidMemoId' , function ( ) {
133+ it ( 'should validate correct memoIds' , function ( ) {
134+ basecoin . isValidMemoId ( '0' ) . should . equal ( true ) ;
135+ basecoin . isValidMemoId ( '1' ) . should . equal ( true ) ;
136+ basecoin . isValidMemoId ( '12345' ) . should . equal ( true ) ;
137+ basecoin . isValidMemoId ( '999999999999' ) . should . equal ( true ) ;
138+ } ) ;
139+
140+ it ( 'should reject invalid memoIds' , function ( ) {
141+ basecoin . isValidMemoId ( '' ) . should . equal ( false ) ;
142+ basecoin . isValidMemoId ( '-1' ) . should . equal ( false ) ;
143+ basecoin . isValidMemoId ( '1.5' ) . should . equal ( false ) ;
144+ basecoin . isValidMemoId ( 'abc' ) . should . equal ( false ) ;
145+ basecoin . isValidMemoId ( '01' ) . should . equal ( false ) ; // Leading zero
146+ basecoin . isValidMemoId ( '00' ) . should . equal ( false ) ;
147+ } ) ;
148+ } ) ;
149+
45150 describe ( 'Testnet' , function ( ) {
46151 let testnetBasecoin ;
47152
@@ -59,5 +164,9 @@ describe('Tempo Coin', function () {
59164 testnetBasecoin . getFullName ( ) . should . equal ( 'Testnet Tempo' ) ;
60165 testnetBasecoin . getBaseFactor ( ) . should . equal ( 1e18 ) ;
61166 } ) ;
167+
168+ it ( 'should validate address with memoId on testnet' , function ( ) {
169+ testnetBasecoin . isValidAddress ( '0x2476602c78e9a5e0563320c78878faa3952b256f?memoId=8' ) . should . equal ( true ) ;
170+ } ) ;
62171 } ) ;
63172} ) ;
0 commit comments