@@ -4,7 +4,7 @@ import {expect, use} from 'chai';
44import chaiAsPromised from 'chai-as-promised' ;
55import { Agent as HttpAgent } from 'http' ;
66import { Agent as HttpsAgent } from 'https' ;
7- import { match , mock , spy , useFakeTimers , SinonFakeTimers } from 'sinon' ;
7+ import { match , mock , spy , stub , useFakeTimers , SinonFakeTimers } from 'sinon' ;
88import sinonChai from 'sinon-chai' ;
99import { fail } from 'assert' ;
1010
@@ -5914,7 +5914,7 @@ describe('Connection', function () {
59145914 subscriptionId = connection . onAccountChange (
59155915 owner . publicKey ,
59165916 resolve ,
5917- 'confirmed' ,
5917+ { commitment : 'confirmed' } ,
59185918 ) ;
59195919 } ,
59205920 ) ;
@@ -6394,4 +6394,125 @@ describe('Connection', function () {
63946394 } ) ;
63956395 } ) . timeout ( 5 * 1000 ) ;
63966396 }
6397+
6398+ it ( 'passes the commitment/encoding to the RPC when calling `onAccountChange`' , ( ) => {
6399+ const connection = new Connection ( url ) ;
6400+ const rpcRequestMethod = stub (
6401+ connection ,
6402+ // @ts -expect-error This method is private, but none the less this spy will work.
6403+ '_makeSubscription' ,
6404+ ) ;
6405+ const mockCallback = ( ) => { } ;
6406+ connection . onAccountChange ( PublicKey . default , mockCallback , {
6407+ commitment : 'processed' ,
6408+ encoding : 'base64+zstd' ,
6409+ } ) ;
6410+ expect ( rpcRequestMethod ) . to . have . been . calledWithExactly (
6411+ {
6412+ callback : mockCallback ,
6413+ method : 'accountSubscribe' ,
6414+ unsubscribeMethod : 'accountUnsubscribe' ,
6415+ } ,
6416+ [
6417+ match . any ,
6418+ match
6419+ . has ( 'commitment' , 'processed' )
6420+ . and ( match . has ( 'encoding' , 'base64+zstd' ) ) ,
6421+ ] ,
6422+ ) ;
6423+ } ) ;
6424+ it ( 'passes the commitment to the RPC when the deprecated signature of `onAccountChange` is used' , ( ) => {
6425+ const connection = new Connection ( url ) ;
6426+ const rpcRequestMethod = stub (
6427+ connection ,
6428+ // @ts -expect-error This method is private, but none the less this spy will work.
6429+ '_makeSubscription' ,
6430+ ) ;
6431+ const mockCallback = ( ) => { } ;
6432+ connection . onAccountChange ( PublicKey . default , mockCallback , 'processed' ) ;
6433+ expect ( rpcRequestMethod ) . to . have . been . calledWithExactly (
6434+ {
6435+ callback : mockCallback ,
6436+ method : 'accountSubscribe' ,
6437+ unsubscribeMethod : 'accountUnsubscribe' ,
6438+ } ,
6439+ [ match . any , match . has ( 'commitment' , 'processed' ) ] ,
6440+ ) ;
6441+ } ) ;
6442+ it ( 'passes the commitment to the RPC when the deprecated signature of `onProgramAccountChange` is used' , ( ) => {
6443+ const connection = new Connection ( url ) ;
6444+ const rpcRequestMethod = stub (
6445+ connection ,
6446+ // @ts -expect-error This method is private, but none the less this spy will work.
6447+ '_makeSubscription' ,
6448+ ) ;
6449+ const mockCallback = ( ) => { } ;
6450+ connection . onProgramAccountChange (
6451+ PublicKey . default ,
6452+ mockCallback ,
6453+ 'processed' /* commitment */ ,
6454+ ) ;
6455+ expect ( rpcRequestMethod ) . to . have . been . calledWithExactly (
6456+ {
6457+ callback : mockCallback ,
6458+ method : 'programSubscribe' ,
6459+ unsubscribeMethod : 'programUnsubscribe' ,
6460+ } ,
6461+ [ match . any , match . has ( 'commitment' , 'processed' ) ] ,
6462+ ) ;
6463+ } ) ;
6464+ it ( 'passes the filters to the RPC when the deprecated signature of `onProgramAccountChange` is used' , ( ) => {
6465+ const connection = new Connection ( url ) ;
6466+ const rpcRequestMethod = stub (
6467+ connection ,
6468+ // @ts -expect-error This method is private, but none the less this spy will work.
6469+ '_makeSubscription' ,
6470+ ) ;
6471+ const mockCallback = ( ) => { } ;
6472+ connection . onProgramAccountChange (
6473+ PublicKey . default ,
6474+ mockCallback ,
6475+ /* commitment */ undefined ,
6476+ /* filters */ [ { dataSize : 123 } ] ,
6477+ ) ;
6478+ expect ( rpcRequestMethod ) . to . have . been . calledWithExactly (
6479+ {
6480+ callback : mockCallback ,
6481+ method : 'programSubscribe' ,
6482+ unsubscribeMethod : 'programUnsubscribe' ,
6483+ } ,
6484+ [ match . any , match . has ( 'filters' , [ { dataSize : 123 } ] ) ] ,
6485+ ) ;
6486+ } ) ;
6487+ it ( 'passes the commitment/encoding/filters to the RPC when calling `onProgramAccountChange`' , ( ) => {
6488+ const connection = new Connection ( url ) ;
6489+ const rpcRequestMethod = stub (
6490+ connection ,
6491+ // @ts -expect-error This method is private, but none the less this spy will work.
6492+ '_makeSubscription' ,
6493+ ) ;
6494+ const mockCallback = ( ) => { } ;
6495+ connection . onProgramAccountChange ( PublicKey . default , mockCallback , {
6496+ commitment : 'processed' ,
6497+ encoding : 'base64+zstd' ,
6498+ filters : [ { dataSize : 123 } ] ,
6499+ } ) ;
6500+ expect ( rpcRequestMethod ) . to . have . been . calledWithExactly (
6501+ {
6502+ callback : mockCallback ,
6503+ method : 'programSubscribe' ,
6504+ unsubscribeMethod : 'programUnsubscribe' ,
6505+ } ,
6506+ [
6507+ match . any ,
6508+ match
6509+ . has ( 'commitment' , 'processed' )
6510+ . and (
6511+ match
6512+ . has ( 'encoding' , 'base64+zstd' )
6513+ . and ( match . has ( 'filters' , [ { dataSize : 123 } ] ) ) ,
6514+ ) ,
6515+ ] ,
6516+ ) ;
6517+ } ) ;
63976518} ) ;
0 commit comments