Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/NOTICK-close-ports-before-PR-tes…
Browse files Browse the repository at this point in the history
…t' into tudor/add_submit_tx_validator_error
  • Loading branch information
tudor-malene committed Feb 14, 2024
2 parents c8e9932 + e43a8a3 commit 2016e42
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 20 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ jobs:
- name: Download eth2network binaries
run: go test ./... -v -count=1 -run TestEnsureBinariesAreAvail

# Close specified ports using lsof before testing / local port list compiled from ./integration/constants.go
- name: Close Integration Test Ports
run: |
lowest_port=8000 # Lowest starting port
highest_port=58000 # Highest port considering the offset
additional_ports=(80 81 99) # Additional specific ports
# Find processes listening on ports within the range and kill them
for pid in $(lsof -iTCP:$lowest_port-$highest_port -sTCP:LISTEN -t); do
echo "Killing process $pid on one of the ports from $lowest_port to $highest_port"
kill $pid || true
done
# Close additional specific ports
for port in "${additional_ports[@]}"; do
for pid in $(lsof -ti TCP:$port); do
echo "Killing process $pid on port $port"
kill $pid || true
done
done
- name: Test
run: go test --failfast -v ./... -count=1 -timeout 5m

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-ten-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
name: ${{ github.event.inputs.testnet_type }}-fe-ten-scan
location: "uksouth"
restart-policy: "Never"
environment-variables: NEXT_PUBLIC_API_HOST=https://${{ github.event.inputs.testnet_type }}-api.obscuroscan.io NEXT_PUBLIC_FE_VERSION=${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }}
environment-variables: NEXT_PUBLIC_API_HOST=https://${{ github.event.inputs.testnet_type }}-api.tenscan.io NEXT_PUBLIC_FE_VERSION=${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }}
command-line: npm run start-prod
ports: "80"
cpu: 2
Expand Down
46 changes: 35 additions & 11 deletions tools/walletextension/accountmanager/account_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ func (m *AccountManager) createClientsForAccounts(accounts []wecommon.AccountDB,
return clients, nil
}

// todo - better way
const notAuthorised = "not authorised"

var platformAuthorisedCalls = map[string]bool{
rpc.GetBalance: true,
// rpc.GetCode, //todo
rpc.GetTransactionCount: true,
rpc.GetTransactionReceipt: true,
rpc.GetLogs: true,
}

func (m *AccountManager) executeCall(rpcReq *wecommon.RPCRequest, rpcResp *interface{}) error {
m.accountsMutex.RLock()
defer m.accountsMutex.RUnlock()
Expand All @@ -217,6 +228,11 @@ func (m *AccountManager) executeCall(rpcReq *wecommon.RPCRequest, rpcResp *inter
// request didn't fail, we don't need to continue trying the other clients
return nil
}
// platform calls return a standard error for calls that are not authorised.
// any other error can be returned early
if platformAuthorisedCalls[rpcReq.Method] && err.Error() != notAuthorised {
return err
}
}
// every attempt errored
return err
Expand All @@ -237,20 +253,28 @@ func (m *AccountManager) suggestAccountClient(req *wecommon.RPCRequest, accClien
return client
}
}

// todo - more calls
if req.Method == rpc.Call {
switch req.Method {
case rpc.Call, rpc.EstimateGas:
return m.handleEthCall(req, accClients)
} else if req.Method == rpc.GetBalance {
if len(req.Params) == 0 {
return nil
}
requestedAddress, err := gethencoding.ExtractAddress(req.Params[0])
if err == nil {
return accClients[*requestedAddress]
}
case rpc.GetBalance:
return extractAddress(0, req.Params, accClients)
case rpc.GetLogs:
return extractAddress(1, req.Params, accClients)
case rpc.GetTransactionCount:
return extractAddress(0, req.Params, accClients)
default:
return nil
}
}

func extractAddress(pos int, params []interface{}, accClients map[gethcommon.Address]*rpc.EncRPCClient) *rpc.EncRPCClient {
if len(params) < pos+1 {
return nil
}
requestedAddress, err := gethencoding.ExtractAddress(params[pos])
if err == nil {
return accClients[*requestedAddress]
}
return nil
}

Expand Down
16 changes: 8 additions & 8 deletions tools/walletextension/frontend/src/services/useGatewayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ const useGatewayService = () => {
};

const connectToTenTestnet = async () => {
showToast(ToastType.INFO, "Connecting to Obscuro Testnet...");
showToast(ToastType.INFO, "Connecting to Ten Testnet...");
setLoading(true);
try {
if (await isTenChain()) {
if (!token || !isValidTokenFormat(token)) {
showToast(
ToastType.DESTRUCTIVE,
"Existing Obscuro Testnet detected in MetaMask. Please remove before hitting begin"
"Existing Ten Testnet detected in MetaMask. Please remove before hitting begin"
);
return;
}
}
showToast(ToastType.INFO, "Switching to Obscuro Testnet...");
showToast(ToastType.INFO, "Switching to Ten Testnet...");
const switched = await switchToTenNetwork();
showToast(ToastType.SUCCESS, `Switched to Obscuro Testnet: ${switched}`);
showToast(ToastType.SUCCESS, `Switched to Ten Testnet: ${switched}`);
// SWITCHED_CODE=4902; error 4902 means that the chain does not exist
if (
switched === SWITCHED_CODE ||
!isValidTokenFormat(await getToken(provider))
) {
showToast(ToastType.INFO, "Adding Obscuro Testnet...");
showToast(ToastType.INFO, "Adding Ten Testnet...");
const user = await joinTestnet();
const rpcUrls = [
`${tenGatewayAddress}/${tenGatewayVersion}/?token=${user}`,
];
await addNetworkToMetaMask(rpcUrls);
showToast(ToastType.SUCCESS, "Added Obscuro Testnet");
showToast(ToastType.SUCCESS, "Added Ten Testnet");
}

if (!(await isMetamaskConnected())) {
showToast(ToastType.INFO, "No accounts found, connecting...");
await connectAccounts();
showToast(ToastType.SUCCESS, "Connected to Obscuro Testnet");
showToast(ToastType.SUCCESS, "Connected to Ten Testnet");
}
await fetchUserAccounts();
} catch (error: any) {
Expand All @@ -81,7 +81,7 @@ const useGatewayService = () => {
try {
return await fetchTestnetStatus();
} catch (error) {
showToast(ToastType.DESTRUCTIVE, "Unable to connect to Obscuro Testnet");
showToast(ToastType.DESTRUCTIVE, "Unable to connect to Ten Testnet");
throw error;
}
};
Expand Down

0 comments on commit 2016e42

Please sign in to comment.