11import * as assert from "assert" ;
22
3- import { getAliceSigner , getDevnetApi , waitForTransactionCompletion , convertPublicKeyToMultiAddress , getRandomSubstrateKeypair , getSignerFromKeypair } from "../src/substrate"
3+ import { getDevnetApi , getRandomSubstrateKeypair } from "../src/substrate"
44import { getPublicClient } from "../src/utils" ;
5- import { ETH_LOCAL_URL , SUB_LOCAL_URL } from "../src/config" ;
5+ import { ETH_LOCAL_URL } from "../src/config" ;
66import { devnet } from "@polkadot-api/descriptors"
77import { PublicClient } from "viem" ;
8- import { PolkadotSigner , TypedApi } from "polkadot-api" ;
8+ import { TypedApi } from "polkadot-api" ;
99import { toViemAddress , convertPublicKeyToSs58 } from "../src/address-utils"
1010import { IAlphaABI , IALPHA_ADDRESS } from "../src/contracts/alpha"
11- import { u64 } from "@polkadot-api/substrate-bindings" ;
12-
11+ import { forceSetBalanceToSs58Address , addNewSubnetwork , startCall } from "../src/subtensor" ;
1312describe ( "Test Alpha Precompile" , ( ) => {
1413 // init substrate part
1514 const hotkey = getRandomSubstrateKeypair ( ) ;
@@ -18,60 +17,20 @@ describe("Test Alpha Precompile", () => {
1817
1918 let api : TypedApi < typeof devnet > ;
2019
21- // sudo account alice as signer
22- let alice : PolkadotSigner ;
23-
2420 // init other variable
2521 let subnetId = 0 ;
2622
2723 before ( async ( ) => {
2824 // init variables got from await and async
2925 publicClient = await getPublicClient ( ETH_LOCAL_URL )
3026 api = await getDevnetApi ( )
31- alice = await getAliceSigner ( ) ;
32-
33- // Fund the hotkey account
34- {
35- const multiAddress = convertPublicKeyToMultiAddress ( hotkey . publicKey )
36- const internalCall = api . tx . Balances . force_set_balance ( { who : multiAddress , new_free : BigInt ( 1e12 ) } )
37- const tx = api . tx . Sudo . sudo ( { call : internalCall . decodedCall } )
38-
39- await waitForTransactionCompletion ( api , tx , alice )
40- . then ( ( ) => { } )
41- . catch ( ( error ) => { console . log ( `transaction error ${ error } ` ) } ) ;
42- }
43-
44- // Fund the coldkey account
45- {
46- const multiAddress = convertPublicKeyToMultiAddress ( coldkey . publicKey )
47- const internalCall = api . tx . Balances . force_set_balance ( { who : multiAddress , new_free : BigInt ( 1e12 ) } )
48- const tx = api . tx . Sudo . sudo ( { call : internalCall . decodedCall } )
49-
50- await waitForTransactionCompletion ( api , tx , alice )
51- . then ( ( ) => { } )
52- . catch ( ( error ) => { console . log ( `transaction error ${ error } ` ) } ) ;
53- }
54-
55- // Register a new subnet
56- const signer = getSignerFromKeypair ( coldkey )
57- const registerNetworkTx = api . tx . SubtensorModule . register_network ( { hotkey : convertPublicKeyToSs58 ( hotkey . publicKey ) } )
58- await waitForTransactionCompletion ( api , registerNetworkTx , signer )
59- . then ( ( ) => { } )
60- . catch ( ( error ) => { console . log ( `transaction error ${ error } ` ) } ) ;
61-
62- // Get the newly created subnet ID
63- let totalNetworks = await api . query . SubtensorModule . TotalNetworks . getValue ( )
64- assert . ok ( totalNetworks > 1 )
65- subnetId = totalNetworks - 1
66-
67- // Register a neuron on the subnet if needed
68- let uid_count = await api . query . SubtensorModule . SubnetworkN . getValue ( subnetId )
69- if ( uid_count === 0 ) {
70- const tx = api . tx . SubtensorModule . burned_register ( { hotkey : convertPublicKeyToSs58 ( hotkey . publicKey ) , netuid : subnetId } )
71- await waitForTransactionCompletion ( api , tx , signer )
72- . then ( ( ) => { } )
73- . catch ( ( error ) => { console . log ( `transaction error ${ error } ` ) } ) ;
74- }
27+
28+ await forceSetBalanceToSs58Address ( api , convertPublicKeyToSs58 ( hotkey . publicKey ) )
29+ await forceSetBalanceToSs58Address ( api , convertPublicKeyToSs58 ( coldkey . publicKey ) )
30+
31+ let netuid = await addNewSubnetwork ( api , hotkey , coldkey )
32+ await startCall ( api , netuid , coldkey )
33+
7534 } )
7635
7736 describe ( "Alpha Price Functions" , ( ) => {
0 commit comments