@@ -48,6 +48,7 @@ const buildSubgraphID = (account: string, seqID: BigNumber): string =>
48
48
describe ( 'GNS' , ( ) => {
49
49
let me : Account
50
50
let other : Account
51
+ let another : Account
51
52
let governor : Account
52
53
53
54
let fixture : NetworkFixture
@@ -444,6 +445,34 @@ describe('GNS', () => {
444
445
return tx
445
446
}
446
447
448
+ const transferSignal = async (
449
+ subgraphID : string ,
450
+ owner : Account ,
451
+ recipient : Account ,
452
+ amount : BigNumber ,
453
+ ) : Promise < ContractTransaction > => {
454
+ // Before state
455
+ const beforeOwnerNSignal = await gns . getCuratorSignal ( subgraphID , owner . address )
456
+ const beforeRecipientNSignal = await gns . getCuratorSignal ( subgraphID , recipient . address )
457
+
458
+ // Transfer
459
+ const tx = gns . connect ( owner . signer ) . transferSignal ( subgraphID , recipient . address , amount )
460
+
461
+ await expect ( tx )
462
+ . emit ( gns , 'SignalTransferred' )
463
+ . withArgs ( subgraphID , owner . address , recipient . address , amount )
464
+
465
+ // After state
466
+ const afterOwnerNSignal = await gns . getCuratorSignal ( subgraphID , owner . address )
467
+ const afterRecipientNSignal = await gns . getCuratorSignal ( subgraphID , recipient . address )
468
+
469
+ // Check state
470
+ expect ( afterOwnerNSignal ) . eq ( beforeOwnerNSignal . sub ( amount ) )
471
+ expect ( afterRecipientNSignal ) . eq ( beforeRecipientNSignal . add ( amount ) )
472
+
473
+ return tx
474
+ }
475
+
447
476
const withdraw = async ( account : Account , subgraphID : string ) : Promise < ContractTransaction > => {
448
477
// Before state
449
478
const beforeCuratorNSignal = await gns . getCuratorSignal ( subgraphID , account . address )
@@ -475,7 +504,7 @@ describe('GNS', () => {
475
504
}
476
505
477
506
before ( async function ( ) {
478
- ; [ me , other , governor ] = await getAccounts ( )
507
+ ; [ me , other , governor , another ] = await getAccounts ( )
479
508
fixture = new NetworkFixture ( )
480
509
; ( { grt, curation, gns } = await fixture . load ( governor . signer ) )
481
510
newSubgraph0 = buildSubgraph ( )
@@ -531,7 +560,7 @@ describe('GNS', () => {
531
560
532
561
it ( 'revert set to empty address' , async function ( ) {
533
562
const tx = gns . connect ( governor . signer ) . setSubgraphNFT ( AddressZero )
534
- await expect ( tx ) . revertedWith ( 'NFT must be valid ' )
563
+ await expect ( tx ) . revertedWith ( 'NFT address cant be zero ' )
535
564
} )
536
565
537
566
it ( 'revert set to non-contract' , async function ( ) {
@@ -824,6 +853,46 @@ describe('GNS', () => {
824
853
} )
825
854
} )
826
855
856
+ describe ( 'transferSignal()' , async function ( ) {
857
+ let subgraph : Subgraph
858
+ let otherNSignal : BigNumber
859
+
860
+ beforeEach ( async ( ) => {
861
+ subgraph = await publishNewSubgraph ( me , newSubgraph0 )
862
+ await mintSignal ( other , subgraph . id , tokens10000 )
863
+ otherNSignal = await gns . getCuratorSignal ( subgraph . id , other . address )
864
+ } )
865
+
866
+ it ( 'should transfer signal from one curator to another' , async function ( ) {
867
+ await transferSignal ( subgraph . id , other , another , otherNSignal )
868
+ } )
869
+ it ( 'should fail when transfering to zero address' , async function ( ) {
870
+ const tx = gns
871
+ . connect ( other . signer )
872
+ . transferSignal ( subgraph . id , ethers . constants . AddressZero , otherNSignal )
873
+ await expect ( tx ) . revertedWith ( 'GNS: Curator cannot transfer to the zero address' )
874
+ } )
875
+ it ( 'should fail when name signal is disabled' , async function ( ) {
876
+ await deprecateSubgraph ( me , subgraph . id )
877
+ const tx = gns
878
+ . connect ( other . signer )
879
+ . transferSignal ( subgraph . id , another . address , otherNSignal )
880
+ await expect ( tx ) . revertedWith ( 'GNS: Must be active' )
881
+ } )
882
+ it ( 'should fail if you try to transfer on a non existing name' , async function ( ) {
883
+ const subgraphID = randomHexBytes ( 32 )
884
+ const tx = gns
885
+ . connect ( other . signer )
886
+ . transferSignal ( subgraphID , another . address , otherNSignal )
887
+ await expect ( tx ) . revertedWith ( 'GNS: Must be active' )
888
+ } )
889
+ it ( 'should fail when the curator tries to transfer more signal than they have' , async function ( ) {
890
+ const tx = gns
891
+ . connect ( other . signer )
892
+ . transferSignal ( subgraph . id , another . address , otherNSignal . add ( otherNSignal ) )
893
+ await expect ( tx ) . revertedWith ( 'GNS: Curator transfer amount exceeds balance' )
894
+ } )
895
+ } )
827
896
describe ( 'withdraw()' , async function ( ) {
828
897
let subgraph : Subgraph
829
898
0 commit comments