Skip to content

Commit

Permalink
fix(affiliate): Use DB transaction for username generation; add more …
Browse files Browse the repository at this point in the history
…stats for update… (backport #2579) (#2581)

Co-authored-by: Teddy Ding <teddy@dydx.exchange>
  • Loading branch information
mergify[bot] and teddyding authored Nov 18, 2024
1 parent 3c63668 commit a2ea55f
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,65 @@ import {
generateUsernameForSubaccount,
} from '../../src/helpers/usernames-helper';

describe('usernames-helper', () => {
it('Check result and determinism of username username', () => {
const addresses = [
'dydx1gf4xlnpulkyex74asxxhg9ye05r28cxdd69s9u',
'dydx10fx7sy6ywd5senxae9dwytf8jxek3t2gcen2vs',
'dydx1t72ww7qzdx5rjlpp6cq0cqy09qlsjj7e4kpuyt',
'dydx1wau5mja7j7zdavtfq9lu7ejef05hm6ffenlcsn',
'dydx168pjt8rkru35239fsqvz7rzgeclakp49zx3aum',
'dydx1df84hz7y0dd3mrqcv3vrhw9wdttelul8edqmvp',
'dydx16h7p7f4dysrgtzptxx2gtpt5d8t834g9dj830z',
'dydx15u9tppy5e2pdndvlrvafxqhuurj9mnpdstzj6z',
'dydx1q54yvrslnu0xp4drpde6f4e0k2ap9efss5hpsd',
'dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4',
'dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc565lnf',
'dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc575lnf',
];
const addresses = [
'dydx1gf4xlnpulkyex74asxxhg9ye05r28cxdd69s9u',
'dydx10fx7sy6ywd5senxae9dwytf8jxek3t2gcen2vs',
'dydx1wau5mja7j7zdavtfq9lu7ejef05hm6ffenlcsn',
'dydx1df84hz7y0dd3mrqcv3vrhw9wdttelul8edqmvp',
'dydx16h7p7f4dysrgtzptxx2gtpt5d8t834g9dj830z',
'dydx15u9tppy5e2pdndvlrvafxqhuurj9mnpdstzj6z',
'dydx1q54yvrslnu0xp4drpde6f4e0k2ap9efss5hpsd',
'dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc565lnf',
'dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc575lnf',
'dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4',
'dydx1c05rgh22wg5pmaufnj8z77kla8fgrgkrth6hlj',
'dydx1qvsqtewdxqdpj5gnkl8usqz3yplpkgs52wv4fy',
];

describe('usernames-helper', () => {
it('Check result of generated username', () => {
const expectedUsernames = [
'CushyHandVE6',
'AmpleCubeLKI',
'AwareFoodHGP',
'LoudLandXWV',
'MossyStraw2JJ',
'BoldGapOGY',
'ZoomEraQE0',
'WiryFernLEC',
'RudeFuel59E',
'MacroMealFK5',
'HappySnapWTT',
'BumpyEdgeH5Y',
'CurlyHallVE6',
'AmpleCrownLKI',
'LoneLawXWV',
'BlueGapOGY',
'ZippyElfQE0',
'WindyFaxLEC',
'RoyalFruit59E',
'GreenSnowWTT',
'BubblyEarH5Y',
'LunarMatFK5',
'SubtleDig25M',
'HillyAccess1C7',
];

const gotUserNames = [];
for (let i = 0; i < addresses.length; i++) {
const address = addresses[i];
for (let j = 0; j < 10; j++) {
const names = new Set();
for (let k = 0; k < 10; k++) {
const username: string = generateUsernameForSubaccount(address, 0, k);
if (k === 0) {
expect(username).toEqual(expectedUsernames[i]);
}
names.add(username);
const namesForOneAddress = new Set();
for (let k = 0; k < 10; k++) {
const username: string = generateUsernameForSubaccount(address, 0, k);
if (k === 0) {
gotUserNames.push(username);
}
// for same address, difference nonce should result in different username
expect(names.size).toEqual(10);
namesForOneAddress.add(username);
}
// for same address, difference nonce should result in different username
expect(namesForOneAddress.size).toEqual(10);
}
expect(gotUserNames).toEqual(expectedUsernames);
});

it('Check determinism of generated username', () => {
for (let i = 0; i < addresses.length; i++) {
const address = addresses[i];
const namesForOneAddress = new Set();
for (let k = 0; k < 10; k++) {
const username: string = generateUsernameForSubaccount(address, 0, 0);
namesForOneAddress.add(username);
}
// for same address, difference nonce should result in different username
expect(namesForOneAddress.size).toEqual(1);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe('subaccount-username-generator', () => {
{}, [], {});

const expectedUsernames = [
'BumpyEdgeH5Y', // dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc575lnf
'HappySnapWTT', // dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc565lnf
'MacroMealFK5', // dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4
'BubblyEarH5Y', // dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc575lnf
'GreenSnowWTT', // dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc565lnf
'LunarMatFK5', // dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4
];
expect(subaccountsWithUsernamesAfter.length).toEqual(subaccountsLength);
for (let i = 0; i < expectedUsernames.length; i++) {
Expand Down
11 changes: 1 addition & 10 deletions indexer/services/roundtable/src/helpers/adjectives.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@
"hip",
"holy",
"honest",
"hot",
"huge",
"humble",
"humid",
"husky",
"icky",
"icy",
Expand Down Expand Up @@ -190,9 +188,7 @@
"lone",
"long",
"loud",
"lousy",
"loved",
"low",
"loyal",
"lucid",
"lucky",
Expand Down Expand Up @@ -234,7 +230,6 @@
"open",
"other",
"oval",
"pale",
"paltry",
"parched",
"pastel",
Expand Down Expand Up @@ -270,7 +265,6 @@
"rough",
"round",
"royal",
"rude",
"rusty",
"sacred",
"sad",
Expand Down Expand Up @@ -349,11 +343,9 @@
"umber",
"unique",
"unruly",
"untidy",
"upbeat",
"upper",
"urban",
"used",
"vague",
"vain",
"valid",
Expand All @@ -378,6 +370,5 @@
"zany",
"zero",
"zesty",
"zippy",
"zoom"
"zippy"
]
14 changes: 0 additions & 14 deletions indexer/services/roundtable/src/helpers/nouns.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"bone",
"book",
"boot",
"born",
"boss",
"bow",
"box",
Expand All @@ -88,7 +87,6 @@
"bull",
"bump",
"bus",
"bush",
"button",
"buy",
"cab",
Expand Down Expand Up @@ -197,7 +195,6 @@
"dust",
"ear",
"earth",
"eat",
"edge",
"egg",
"elbow",
Expand All @@ -214,7 +211,6 @@
"ferret",
"fiber",
"file",
"fill",
"film",
"fire",
"fish",
Expand All @@ -226,7 +222,6 @@
"flute",
"fly",
"fog",
"fold",
"food",
"fork",
"form",
Expand All @@ -238,7 +233,6 @@
"fun",
"game",
"gap",
"gate",
"gem",
"gift",
"giraffe",
Expand Down Expand Up @@ -270,8 +264,6 @@
"hill",
"hippo",
"hit",
"hold",
"hole",
"home",
"honey",
"hood",
Expand Down Expand Up @@ -348,7 +340,6 @@
"melt",
"meme",
"menu",
"mess",
"meter",
"mile",
"mill",
Expand Down Expand Up @@ -466,15 +457,11 @@
"sign",
"silk",
"sir",
"sit",
"ski",
"sky",
"sled",
"slip",
"slow",
"smile",
"smoke",
"snap",
"snow",
"soap",
"sock",
Expand Down Expand Up @@ -502,7 +489,6 @@
"store",
"storm",
"straw",
"sum",
"summer",
"sun",
"swan",
Expand Down
Loading

0 comments on commit a2ea55f

Please sign in to comment.