@@ -1644,6 +1644,60 @@ for (const extension of ALL_EXTENSIONS) {
16441644 } ,
16451645 timeout ,
16461646 )
1647+
1648+ it ( 'signSapient handles selector-only self increment call consistently' , async ( ) => {
1649+ const identityPrivateKey = Secp256k1 . randomPrivateKey ( )
1650+ const identityAddress = Address . fromPublicKey ( Secp256k1 . getPublicKey ( { privateKey : identityPrivateKey } ) )
1651+ const stateProvider = new State . Local . Provider ( )
1652+
1653+ const explicitSigner = new Signers . Session . Explicit ( Secp256k1 . randomPrivateKey ( ) , {
1654+ chainId : 0 ,
1655+ valueLimit : 0n ,
1656+ deadline : BigInt ( Math . floor ( Date . now ( ) / 1000 ) + 3600 ) ,
1657+ permissions : [ PermissionBuilder . for ( EMITTER_ADDRESS1 ) . allowAll ( ) . build ( ) ] ,
1658+ } )
1659+
1660+ const sessionTopology = SessionConfig . addExplicitSession ( SessionConfig . emptySessionsTopology ( identityAddress ) , {
1661+ ...explicitSigner . sessionPermissions ,
1662+ signer : explicitSigner . address ,
1663+ } )
1664+ await stateProvider . saveTree ( SessionConfig . sessionsTopologyToConfigurationTree ( sessionTopology ) )
1665+ const imageHash = GenericTree . hash ( SessionConfig . sessionsTopologyToConfigurationTree ( sessionTopology ) )
1666+
1667+ const wallet = await Wallet . fromConfiguration (
1668+ {
1669+ threshold : 1n ,
1670+ checkpoint : 0n ,
1671+ topology : [ { type : 'sapient-signer' , address : extension . sessions , weight : 1n , imageHash } , Hex . random ( 32 ) ] ,
1672+ } ,
1673+ { stateProvider } ,
1674+ )
1675+ const sessionManager = new Signers . SessionManager ( wallet , {
1676+ sessionManagerAddress : extension . sessions ,
1677+ explicitSigners : [ explicitSigner ] ,
1678+ } )
1679+
1680+ const payload : Payload . Parented = {
1681+ type : 'call' ,
1682+ nonce : 0n ,
1683+ space : 0n ,
1684+ calls : [
1685+ {
1686+ to : extension . sessions ,
1687+ data : AbiFunction . getSelector ( Constants . INCREMENT_USAGE_LIMIT ) ,
1688+ value : 0n ,
1689+ gasLimit : 0n ,
1690+ delegateCall : false ,
1691+ onlyFallback : false ,
1692+ behaviorOnError : 'revert' ,
1693+ } ,
1694+ ] ,
1695+ parentWallets : [ wallet . address ] ,
1696+ }
1697+
1698+ const signature = await sessionManager . signSapient ( wallet . address , 0 , payload , imageHash )
1699+ expect ( signature . type ) . toBe ( 'sapient' )
1700+ } )
16471701 } )
16481702 } )
16491703}
0 commit comments