11import * as assert from "assert" ;
22
33import { getAliceSigner , getDevnetApi , getRandomSubstrateKeypair } from "../src/substrate"
4- import { generateRandomEthersWallet , generateRandomEthWallet } from "../src/utils" ;
4+ import { generateRandomEthersWallet } from "../src/utils" ;
55import { devnet , MultiAddress } from "@polkadot-api/descriptors"
6- import { hexToU8a } from "@polkadot/util" ;
76import { PolkadotSigner , TypedApi } from "polkadot-api" ;
8- import { convertH160ToSS58 , convertPublicKeyToSs58 } from "../src/address-utils"
7+ import { convertH160ToPublicKey , convertH160ToSS58 , convertPublicKeyToSs58 } from "../src/address-utils"
98import { IProxyABI , IPROXY_ADDRESS } from "../src/contracts/proxy"
10- import { keccak256 , ethers } from 'ethers' ;
9+ import { ethers } from 'ethers' ;
1110import { forceSetBalanceToEthAddress , forceSetBalanceToSs58Address } from "../src/subtensor" ;
12- import { Signer } from "@polkadot/api/types" ;
1311import { KeyPair } from "@polkadot-labs/hdkd-helpers" ;
1412
1513import { decodeAddress } from "@polkadot/util-crypto" ;
@@ -49,6 +47,8 @@ async function getProxies(api: TypedApi<typeof devnet>, address: string) {
4947describe ( "Test pure proxy precompile" , ( ) => {
5048 const evmWallet = generateRandomEthersWallet ( ) ;
5149 const evmWallet2 = generateRandomEthersWallet ( ) ;
50+ const evmWallet3 = generateRandomEthersWallet ( ) ;
51+ const delegate = getRandomSubstrateKeypair ( ) ;
5252 const receiver = getRandomSubstrateKeypair ( ) ;
5353
5454 let api : TypedApi < typeof devnet >
@@ -61,7 +61,8 @@ describe("Test pure proxy precompile", () => {
6161
6262 await forceSetBalanceToEthAddress ( api , evmWallet . address )
6363 await forceSetBalanceToEthAddress ( api , evmWallet2 . address )
64-
64+ await forceSetBalanceToEthAddress ( api , evmWallet3 . address )
65+ await forceSetBalanceToSs58Address ( api , convertPublicKeyToSs58 ( delegate . publicKey ) )
6566 } )
6667
6768 it ( "Call createPureProxy, then use proxy to call transfer" , async ( ) => {
@@ -154,4 +155,39 @@ describe("Test pure proxy precompile", () => {
154155 assert . notEqual ( error , undefined , "should fail if proxy not set" )
155156 }
156157 } )
158+
159+ it ( "Call createProxy, then use proxy to call transfer" , async ( ) => {
160+ const proxies = await api . query . Proxy . Proxies . getValue ( convertH160ToSS58 ( evmWallet2 . address ) )
161+ const contract = new ethers . Contract ( IPROXY_ADDRESS , IProxyABI , evmWallet2 )
162+
163+ const type = 0 ;
164+ const delay = 0 ;
165+
166+ const tx = await contract . addProxy ( convertH160ToPublicKey ( evmWallet3 . address ) , type , delay )
167+ await tx . wait ( )
168+
169+
170+ const proxiesAfterAdd = await await api . query . Proxy . Proxies . getValue ( convertH160ToSS58 ( evmWallet2 . address ) )
171+
172+ const length = proxiesAfterAdd [ 0 ] . length
173+ assert . equal ( length , proxies [ 0 ] . length + 1 , "proxy should be set" )
174+ const proxy = proxiesAfterAdd [ 0 ] [ proxiesAfterAdd [ 0 ] . length - 1 ]
175+
176+ assert . equal ( proxy . delegate , convertH160ToSS58 ( evmWallet3 . address ) , "proxy should be set" )
177+
178+
179+ const balance = ( await api . query . System . Account . getValue ( convertPublicKeyToSs58 ( receiver . publicKey ) ) ) . data . free
180+
181+ const amount = 1000000000 ;
182+
183+ const contract2 = new ethers . Contract ( IPROXY_ADDRESS , IProxyABI , evmWallet3 )
184+
185+
186+ const callCode = await getTransferCallCode ( api , receiver , amount )
187+ const tx2 = await contract2 . proxyCall ( convertH160ToPublicKey ( evmWallet2 . address ) , [ type ] , callCode )
188+ await tx2 . wait ( )
189+
190+ const balanceAfter = ( await api . query . System . Account . getValue ( convertPublicKeyToSs58 ( receiver . publicKey ) ) ) . data . free
191+ assert . equal ( balanceAfter , balance + BigInt ( amount ) , "balance should be increased" )
192+ } )
157193} ) ;
0 commit comments