Skip to content

Commit 8af65df

Browse files
author
unconst
committed
alpha tests
1 parent e4ccdfa commit 8af65df

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

pallets/subtensor/src/coinbase/block_step.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
1616
log::debug!("Block emission: {:?}", block_emission);
1717
// --- 3. Run emission through network.
1818
Self::run_coinbase(block_emission);
19-
2019
// --- 4. Set pending children on the epoch; but only after the coinbase has been run.
2120
Self::try_set_pending_children(block_number);
22-
2321
// Return ok.
2422
Ok(())
2523
}

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ fn test_coinbase_alpha_issuance_base() {
216216
});
217217
}
218218

219+
// Test alpha issuance with different subnet prices.
220+
// This test verifies that:
221+
// - Alpha issuance is proportional to subnet prices
222+
// - Higher priced subnets receive more TAO emission
223+
// - Alpha issuance is correctly calculated based on price ratios
219224
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_coinbase_alpha_issuance_different --exact --show-output --nocapture
220225
#[test]
221226
fn test_coinbase_alpha_issuance_different() {
@@ -249,3 +254,76 @@ fn test_coinbase_alpha_issuance_different() {
249254
}
250255

251256

257+
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_coinbase_alpha_issuance_with_cap_trigger --exact --show-output --nocapture
258+
#[test]
259+
fn test_coinbase_alpha_issuance_with_cap_trigger() {
260+
new_test_ext(1).execute_with(|| {
261+
let netuid1: u16 = 1;
262+
let netuid2: u16 = 2;
263+
let emission: u64 = 1_000_000;
264+
add_network(netuid1, 1, 0);
265+
add_network(netuid2, 1, 0);
266+
// Make subnets dynamic.
267+
SubnetMechanism::<Test>::insert(netuid1, 1);
268+
SubnetMechanism::<Test>::insert(netuid2, 1);
269+
// Setup prices 1000000
270+
let initial: u64 = 1_000;
271+
let initial_alpha: u64 = initial * 1000000;
272+
SubnetTAO::<Test>::insert(netuid1, initial);
273+
SubnetAlphaIn::<Test>::insert(netuid1, initial_alpha); // Make price extremely low.
274+
SubnetTAO::<Test>::insert(netuid2, initial);
275+
SubnetAlphaIn::<Test>::insert(netuid2, initial_alpha); // Make price extremely low.
276+
// Set subnet prices.
277+
SubnetMovingPrice::<Test>::insert( netuid1, I96F32::from_num(1) );
278+
SubnetMovingPrice::<Test>::insert( netuid2, I96F32::from_num(2) );
279+
// Run coinbase
280+
SubtensorModule::run_coinbase( I96F32::from_num( emission ) );
281+
// tao_in = 333_333
282+
// alpha_in = 333_333/price > 1_000_000_000 --> 1_000_000_000 + initial_alpha
283+
assert_eq!( SubnetAlphaIn::<Test>::get( netuid1 ), initial_alpha + 1_000_000_000 );
284+
assert_eq!( SubnetAlphaOut::<Test>::get( netuid2 ), 1_000_000_000 );
285+
// tao_in = 666_666
286+
// alpha_in = 666_666/price > 1_000_000_000 --> 1_000_000_000 + initial_alpha
287+
assert_eq!( SubnetAlphaIn::<Test>::get( netuid2 ), initial_alpha + 1_000_000_000 );
288+
assert_eq!( SubnetAlphaOut::<Test>::get( netuid2 ), 1_000_000_000 ); // Gets full block emission.
289+
});
290+
}
291+
292+
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_coinbase_alpha_issuance_with_cap_trigger_and_block_emission --exact --show-output --nocapture
293+
#[test]
294+
fn test_coinbase_alpha_issuance_with_cap_trigger_and_block_emission() {
295+
new_test_ext(1).execute_with(|| {
296+
let netuid1: u16 = 1;
297+
let netuid2: u16 = 2;
298+
let emission: u64 = 1_000_000;
299+
add_network(netuid1, 1, 0);
300+
add_network(netuid2, 1, 0);
301+
// Make subnets dynamic.
302+
SubnetMechanism::<Test>::insert(netuid1, 1);
303+
SubnetMechanism::<Test>::insert(netuid2, 1);
304+
// Setup prices 1000000
305+
let initial: u64 = 1_000;
306+
let initial_alpha: u64 = initial * 1000000;
307+
SubnetTAO::<Test>::insert(netuid1, initial);
308+
SubnetAlphaIn::<Test>::insert(netuid1, initial_alpha); // Make price extremely low.
309+
SubnetTAO::<Test>::insert(netuid2, initial);
310+
SubnetAlphaIn::<Test>::insert(netuid2, initial_alpha); // Make price extremely low.
311+
// Set issuance to greater than 21M
312+
SubnetAlphaOut::<Test>::insert(netuid1, 22_000_000_000_000_000 ); // Set issuance above 21M
313+
SubnetAlphaOut::<Test>::insert(netuid2, 22_000_000_000_000_000 ); // Set issuance above 21M
314+
// Set subnet prices.
315+
SubnetMovingPrice::<Test>::insert( netuid1, I96F32::from_num(1) );
316+
SubnetMovingPrice::<Test>::insert( netuid2, I96F32::from_num(2) );
317+
// Run coinbase
318+
SubtensorModule::run_coinbase( I96F32::from_num( emission ) );
319+
// tao_in = 333_333
320+
// alpha_in = 333_333/price > 1_000_000_000 --> 0 + initial_alpha
321+
assert_eq!( SubnetAlphaIn::<Test>::get( netuid1 ), initial_alpha );
322+
assert_eq!( SubnetAlphaOut::<Test>::get( netuid2 ), 22_000_000_000_000_000 );
323+
// tao_in = 666_666
324+
// alpha_in = 666_666/price > 1_000_000_000 --> 0 + initial_alpha
325+
assert_eq!( SubnetAlphaIn::<Test>::get( netuid2 ), initial_alpha );
326+
assert_eq!( SubnetAlphaOut::<Test>::get( netuid2 ), 22_000_000_000_000_000 ); // No emission.
327+
});
328+
}
329+

0 commit comments

Comments
 (0)