1
1
import * as assert from "assert" ;
2
2
3
- import { getAliceSigner , getDevnetApi , waitForTransactionCompletion , convertPublicKeyToMultiAddress , getRandomSubstrateKeypair , getSignerFromKeypair } from "../src/substrate"
3
+ import { getDevnetApi , getRandomSubstrateKeypair } from "../src/substrate"
4
4
import { getPublicClient } from "../src/utils" ;
5
- import { ETH_LOCAL_URL , SUB_LOCAL_URL } from "../src/config" ;
5
+ import { ETH_LOCAL_URL } from "../src/config" ;
6
6
import { devnet } from "@polkadot-api/descriptors"
7
7
import { PublicClient } from "viem" ;
8
- import { PolkadotSigner , TypedApi } from "polkadot-api" ;
8
+ import { TypedApi } from "polkadot-api" ;
9
9
import { toViemAddress , convertPublicKeyToSs58 } from "../src/address-utils"
10
10
import { IAlphaABI , IALPHA_ADDRESS } from "../src/contracts/alpha"
11
- import { u64 } from "@polkadot-api/substrate-bindings" ;
12
-
11
+ import { forceSetBalanceToSs58Address , addNewSubnetwork , startCall } from "../src/subtensor" ;
13
12
describe ( "Test Alpha Precompile" , ( ) => {
14
13
// init substrate part
15
14
const hotkey = getRandomSubstrateKeypair ( ) ;
@@ -18,60 +17,20 @@ describe("Test Alpha Precompile", () => {
18
17
19
18
let api : TypedApi < typeof devnet > ;
20
19
21
- // sudo account alice as signer
22
- let alice : PolkadotSigner ;
23
-
24
20
// init other variable
25
21
let subnetId = 0 ;
26
22
27
23
before ( async ( ) => {
28
24
// init variables got from await and async
29
25
publicClient = await getPublicClient ( ETH_LOCAL_URL )
30
26
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
+
75
34
} )
76
35
77
36
describe ( "Alpha Price Functions" , ( ) => {
0 commit comments