Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Storage Name Checking Script #314

Closed
aurexav opened this issue Sep 26, 2020 · 3 comments · Fixed by #733
Closed

Storage Name Checking Script #314

aurexav opened this issue Sep 26, 2020 · 3 comments · Fixed by #733
Assignees
Labels
S-Security [Security]

Comments

@aurexav
Copy link
Member

aurexav commented Sep 26, 2020

Add to CI

@wuminzhe
Copy link
Contributor

wuminzhe commented Sep 26, 2020

def duplicate?
  excludes = %w[
    support/src/lib.rs
    rpc/runtime-api/src/lib.rs
    rpc/src/lib.rs
  ]
  module_names = []
  storages = []
  Dir["/Users/itering/Projects/darwinia-network/darwinia-common/frame/**/*"].each do |d|
    if d.end_with?("src/lib.rs") && excludes.all? { |e| not d.end_with?(e) }
      module_name = nil
      File.open(d).read.each_line do |line|
        scaned = line.scan /trait Store for Module.* as(.+){/
        if scaned.length > 0
          module_name = scaned[0][0].strip
          module_names << module_name
        end
        
        unless module_name.nil?
          scaned = line.scan /\t{2}pub ([A-Z]\S*)\s*$/
          storages << "#{module_name}_#{scaned[0][0].strip}" if scaned.length > 0

          scaned = line.scan /\t{2}pub ([A-Z]\S*)\s* /
          storages << "#{module_name}_#{scaned[0][0].strip}" if scaned.length > 0
        end
      end

    end
  end
  module_names_ori_count = module_names.length
  storages_ori_count = storages.length

  module_names_count = module_names.uniq.length
  storages_count = storages.uniq.length

  module_names_dup = module_names.detect{ |e| module_names.count(e) > 1 }
  puts "Dup modules: #{module_names_dup}" if (not module_names_dup.nil?) && module_names_dup.length > 0
  storages_dup = storages.detect{ |e| storages.count(e) > 1 }
  puts "Dup storages: #{storages_dup}" if (not storages_dup.nil?) && storages_dup.length > 0

  module_names_ori_count != module_names_count || storages_ori_count != storages_count
end

puts duplicate?

@hackfisher
Copy link
Contributor

@aurexav aurexav self-assigned this Mar 15, 2021
@aurexav aurexav added the S-Security [Security] label Mar 15, 2021
@hackfisher
Copy link
Contributor

Fixed in #733 ?

@aurexav aurexav linked a pull request Aug 10, 2021 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S-Security [Security]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants