@@ -6,6 +6,7 @@ import { EntityAction, EntityType } from "@arkecosystem/core-magistrate-crypto/s
6
6
import {
7
7
EntityAlreadyRegisteredError ,
8
8
EntityAlreadyResignedError ,
9
+ EntityNameAlreadyRegisteredError ,
9
10
EntityNameDoesNotMatchDelegateError ,
10
11
EntityNotRegisteredError ,
11
12
EntitySenderIsNotDelegateError ,
@@ -178,6 +179,62 @@ describe("Entity handler", () => {
178
179
) . rejects . toBeInstanceOf ( StaticFeeMismatchError ) ;
179
180
} ) ;
180
181
182
+ it . each ( [ validRegisters ] ) (
183
+ "should throw when entity name is already registered for same type" ,
184
+ async asset => {
185
+ const transaction = entityBuilder
186
+ . asset ( asset )
187
+ . sign ( senderPassphrase )
188
+ . build ( ) ;
189
+
190
+ const randomPassphrase = "this is another passphrase" ;
191
+ const randomWallet = new Wallets . Wallet ( Identities . Address . fromPassphrase ( randomPassphrase ) ) ;
192
+ randomWallet . balance = Utils . BigNumber . make ( 452765431200000 ) ;
193
+ randomWallet . publicKey = Identities . PublicKey . fromPassphrase ( randomPassphrase ) ;
194
+ // entity name already registered with different wallet and different tx id
195
+ randomWallet . setAttribute ( "entities" , {
196
+ "7950c6a0d096eeb4883237feec12b9f37f36ab9343ff3640904befc75ce32ec2" : {
197
+ type : asset . type ,
198
+ subType : ( asset . subType + 1 ) % 255 , // different subType but still in the range [0, 255]
199
+ data : asset . data ,
200
+ } ,
201
+ } ) ;
202
+ walletManager . reindex ( randomWallet ) ;
203
+
204
+ await expect (
205
+ entityHandler . throwIfCannotBeApplied ( transaction , senderWallet , walletManager ) ,
206
+ ) . rejects . toBeInstanceOf ( EntityNameAlreadyRegisteredError ) ;
207
+ } ,
208
+ ) ;
209
+
210
+ it . each ( [ validRegisters ] ) (
211
+ "should not throw when entity name is registered for a different type" ,
212
+ async asset => {
213
+ const transaction = entityBuilder
214
+ . asset ( asset )
215
+ . sign ( senderPassphrase )
216
+ . build ( ) ;
217
+
218
+ const randomPassphrase = "this is another passphrase" ;
219
+ const randomWallet = new Wallets . Wallet ( Identities . Address . fromPassphrase ( randomPassphrase ) ) ;
220
+ randomWallet . balance = Utils . BigNumber . make ( 452765431200000 ) ;
221
+ randomWallet . publicKey = Identities . PublicKey . fromPassphrase ( randomPassphrase ) ;
222
+ // entity name already registered with different wallet and different tx id
223
+ randomWallet . setAttribute ( "entities" , {
224
+ "7950c6a0d096eeb4883237feec12b9f37f36ab9343ff3640904befc75ce32ec2" : {
225
+ type : ( asset . type + 1 ) % 255 , // different subType but still in the range [0, 255]
226
+ subType : asset . subType ,
227
+ data : asset . data ,
228
+ } ,
229
+ } ) ;
230
+ walletManager . reindex ( randomWallet ) ;
231
+
232
+ await expect (
233
+ entityHandler . throwIfCannotBeApplied ( transaction , senderWallet , walletManager ) ,
234
+ ) . toResolve ( ) ;
235
+ } ,
236
+ ) ;
237
+
181
238
describe ( "Entity delegate" , ( ) => {
182
239
const createEntityDelegateTx = name =>
183
240
entityBuilder
0 commit comments