darwinia-network / darwinia-common

Darwinia Runtime Pallet Library and Pangolin/Pangoro Testnet
https://rust-docs.darwinia.network/darwinia-common
GNU General Public License v3.0
30 stars 9 forks source link

Storage Name Checking Script #314

Closed AurevoirXavier closed 3 years ago

AurevoirXavier commented 4 years ago

Add to CI

wuminzhe commented 4 years ago
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 commented 3 years ago

https://github.com/paritytech/substrate/pull/8123

https://github.com/paritytech/substrate/pull/8038

hackfisher commented 3 years ago

Fixed in #733 ?